我正在尝试将图像从android上传到PHP文件,然后将其保存到服务器..
这里是 android 代码:
File image = new File(file_path);
try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://www.DomainName.com/imageUpload.php");
MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
ContentBody cbFile = new FileBody(image, "image/jpeg");
multipartEntity.addPart("image", cbFile);
post.setEntity(multipartEntity);
client.execute(post, new PhotoUploadResponseHandler());
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.i("IOException", e.toString());
}
PHP文件
<?php
$uploadedFile = $_FILES['image']['name'];
$uploadedType = $_FILES['image']['type'];
$temp = $_FILES['image']['tmp_name'];
$error = $_FILES['image']['error'];
if ($error > 0) {
die("File could not be uploaded. $error");
}
else {
move_uploaded_file($temp, "/Images/".$uploadedFile);
echo "Upload Complete. ".$uploadedType;
}
?>
我面临的问题是,此操作的输出是&#34;上传完成。&#34; ,但指定的路径中没有图像, (/ Images /)在服务器上!
请帮忙