我用photopicker拍摄的照片我尝试使用ASIHTTPRequest上传,如下所示:
NSData *imageData = UIImageJPEGRepresentation(image, 80);
[request setData:imageData withFileName:@"test.jpg" andContentType:@"image/jpg" forKey:@"file"];
问题是,在php结尾处,有这个片段:
$target_path = "files/";
target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "Image: ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "error uploading";
}
然而,无论我上传什么,它都会继续返回上传失败的内容。
答案 0 :(得分:2)
您正在使用“file”键上传文件。在您的PHP脚本中,您尝试以“uploadedfile”的名称/键检索文件,将“uploadedfile”更改为“file”,它应该可以正常工作。