Android 在php服务器上上载图像
我正在尝试在我尝试的服务器上上载图像Android 在php服务器上上载图像,android,image-uploading,Android,Image Uploading,我正在尝试在我尝试的服务器上上载图像 很多方法都没有得到准确的结果 我的php脚本是:- <?php //include "db.php"; if(isset($_POST['action']) && isset($_FILES['arch'])) { if($_POST['action']==='uploadfilefromapp') { $newfile = basename($_FILES['arch'
很多方法都没有得到准确的结果 我的php脚本是:-
<?php
//include "db.php";
if(isset($_POST['action']) && isset($_FILES['arch']))
{
if($_POST['action']==='uploadfilefromapp')
{
$newfile = basename($_FILES['arch']['name']);
if(move_uploaded_file($_FILES['arch']['tmp_name'], "files/".$newfile))
{
echo 'ok!';
/*$userfile_extn = explode(".", strtolower($_FILES['arch']['name']));
echo "extension = ".$userfile_extn;
$media_id = $_REQUEST['file_id'];
mysql_query("UPDATE media SET description= '$userfile_extn' WHERE media_id='$media_id'");
*/
}
else
{
echo 'fail!';
}
}
else
{
echo 'Go away cheater';
}
}
?>
我建议对http请求使用改型库,因为我觉得您可能会发现它使用起来很简单,它允许多部分请求正文和文件上传。这里有一个类似这样的链接:
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("action", "uploadfilefromapp"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
List name-valuepairs=new-ArrayList(2);
添加(新的BasicNameValuePair(“action”,“uploadfilefromapp”);
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
进一步:这个网站有很多多部分上传的例子。大多数情况下,他们使用“uploadedfile”或“uploadedfile”,而您必须使用“arch”name'是文件名。最好的方法是实现一个IntentService并用广播意图通知状态。请从git中检查此代码
您好,这是一个更好的例子:谢谢,但我必须使用上面的php脚本,我不知道应该在哪里使用脚本条件,如“uploadfilefromapp”“arch”
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("action", "uploadfilefromapp"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));