iPhone 网络服务 ASIHTTPRequest

发布于 2024-12-04 15:16:06 字数 634 浏览 1 评论 0原文

我有一张用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

━╋う一瞬間旳綻放 2024-12-11 15:16:06

您正在使用“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文