
正文
安卓php上传数据 安卓 php
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
php网站上传好之后,数据库已经在本地写好,怎么上传到服务器上呢?
用navicat或者phpmyadmin等工具导出sql
在线上数据库建立一个新的数据库,然后用上述工具倒入即可
修改网站代码中的数据库配置文件,将新的数据库ip、用户名和密码写入
相关问答
Q1: php上传功能怎么实现点击浏览在打开文件之后直接上传?
我的博客《用最简单的例子实现jQuery图片即时上传》已经做了详细的介绍,请参考实现。
主要原理:
jQuery上传插件将input type="file"的数据转至一个新生的form当中将其提交,
而表单的target指向新生的iframe,在iframe中做表单提交后的处理,
完成后iframe会重新加载并包含处理结果,通过iframe的load事件便可捕捉并获取处理结果,
回传至原表单所在的页面(feedback)中,实现jQuery即时上传的效果。
而在表单提交的时候,为了实现选择文件后即时提交表单,则使用了input标签的change事件,
只要选择了文件,input的值就会发生变化,此时就可以提交表单进行处理了。
Q2: 安卓上传的图片,PHP服务器怎么接收
print_r($_FILES);
print_r($_POST);
echo file_get_contents('php://input');
$arr = $GLOBALS["HTTP_RAW_POST_DATA"];
print_r($arr);
是不会看到什么结果安卓php上传数据的
因为安卓php上传数据你似乎并没用显示返回数据的代码安卓php上传数据,也不知道返回的数据格式是否符合要求(不合要求也可能不显示)
但你这样
file_put_contents('test.txt', print_r($_FILES, 1));
file_put_contents('test.txt', print_r($_POST, 1), FILE_APPEND);
file_put_contents('test.txt', file_get_contents('php://input'), FILE_APPEND);
$arr = $GLOBALS["HTTP_RAW_POST_DATA"];
file_put_contents('test.txt', print_r($arr, 1), FILE_APPEND);
在 test.txt 中是一定有结果的
Q3: 安卓如何在后台上传图片等资料
public class EX08_11 extends Activity
{
/* 变量声明
* newName:上传后在服务器上的文件名称
* uploadFile:要上传的文件路径
* actionUrl:服务器对应的程序路径 */
// private String newName="345444.jpg";
private String uploadFile="/sdcard/345444.jpg";
private String actionUrl="http://*********/upload.PHP";
private TextView mText1;
private TextView mText2;
private Button mButton;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mText1 = (TextView) findViewById(R.id.myText2);
mText1.setText("文件路径:/n"+uploadFile);
mText2 = (TextView) findViewById(R.id.myText3);
mText2.setText("上传网址:/n"+actionUrl);
/* 设定mButton的onClick事件处理 */
mButton = (Button) findViewById(R.id.myButton);
mButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
uploadFile();
}
});
}
/* 上传文件吹Server的method */
private void uploadFile()
{
// String end = "/r/n";
// String twoHyphens = "--";
String boundary = "*****";
try
{
URL url =new URL(actionUrl);
HttpURLConnection con=(HttpURLConnection)url.openConnection();
/* 允许Input、Output,不使用Cache */
// con.setReadTimeout(5 * 1000);
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
/* 设定传送的method=POST */
con.setRequestMethod("POST");
/* setRequestProperty */
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("Charset", "UTF-8");
con.setRequestProperty("enctype",
"multipart/form-data;boundary="+boundary);
/* 设定DataOutputStream */
DataOutputStream ds =
new DataOutputStream(con.getOutputStream());
/*ds.writeBytes(twoHyphens + boundary + end);
ds.writeBytes("Content-Disposition: form-data; " +
"name=/"file1/";filename=/"" +
newName +"/"" + end);
ds.writeBytes(end); */
/* 取得文件的FileInputStream */
FileInputStream fStream = new FileInputStream(uploadFile);
/* 设定每次写入1024bytes */
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int length = -1;
/* 从文件读取数据到缓冲区 */
while((length = fStream.read(buffer)) != -1)
{
/* 将数据写入DataOutputStream中 */
ds.write(buffer, 0, length);
}
// ds.writeBytes(end);
// ds.writeBytes(twoHyphens + boundary + twoHyphens + end);
/* close streams */
fStream.close();
ds.flush();
/* 取得Response内容 */
InputStream is = con.getInputStream();
int ch;
StringBuffer b =new StringBuffer();
while( ( ch = is.read() ) != -1 )
{
b.append( (char)ch );
}
/* 将Response显示于Dialog */
showDialog(b.toString().trim());
/* 关闭DataOutputStream */
ds.close();
}
catch(Exception e)
{
showDialog(""+e);
}
}
/* 显示Dialog的method */
private void showDialog(String mess)
{
new AlertDialog.Builder(EX08_11.this).setTitle("Message")
.setMessage(mess)
.setNegativeButton("确定",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
}
})
.show();
}
}
PHP代码
[php] view plain copy
$data = file_get_contents('php://input');
$handle = fopen($_SERVER['DOCUMENT_ROOT'].'/image/345444.jpg', 'w');
if ($handle)
{
fwrite($handle,$data);
fclose($handle);
echo "success";
}
Q4: PHP如何做一个接口,向安卓客户端提供数据
其实就是访问这个php文件安卓php上传数据,返回一段数据安卓php上传数据,一般用json,然后安卓可以解析就行安卓php上传数据了安卓php上传数据了。走http协议。
安卓php上传数据的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于安卓 php、安卓php上传数据的信息别忘了在本站进行查找喔。







