iPhone 网络服务 ASIHTTPRequest
我有一张用 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";
}
但是,无论我上传什么,它都会不断返回上传失败的信息。
I have an image taken with the photopicker i try to upload with the ASIHTTPRequest like this:
NSData *imageData = UIImageJPEGRepresentation(image, 80);
[request setData:imageData withFileName:@"test.jpg" andContentType:@"image/jpg" forKey:@"file"];
The issue is, on the php end of things, with this snippet:
$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";
}
However, it keeps returning that the upload has failed, no matter what I upload.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用“file”键上传文件。在您的 php 脚本中,您尝试检索名称/键为“uploadedfile”的文件,将“uploadedfile”更改为“file”,它应该可以工作。
You are uploading the file with the key of "file". In your php script you are trying to retrieve a file at the name / key of "uploadedfile" change "uploadedfile" to "file" and it should work.