ASIHTTPRequest 和 PHP;如何将多个图像流式传输到服务器

发布于 2024-12-13 00:54:47 字数 955 浏览 0 评论 0原文

当我使用以下方法将一些图像发布到我的服务器时:

ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url];
[request setShouldStreamPostDataFromDisk:YES];
[request setData:image withFileName:@"file(0)" andContentType:@"image/jpg" forKey:fileString];
[request setData:image withFileName:@"file(1)" andContentType:@"image/jpg" forKey:fileString];
[request setData:image withFileName:@"file(2)" andContentType:@"image/jpg" forKey:fileString];
[request startAsynchronous];

如何在 PHP 脚本中捕获它?

我正在

for($i = 0; $i<$imageCount; $i++){

$target_path = "files/";

$target_path = $target_path . basename( $_FILES['file($i)']['name']); 

if(move_uploaded_file($_FILES['file($i)']['tmp_name'], $target_path)) {
  echo "Image: ".  basename( $_FILES['uploadedfile']['name']). 
" has been uploaded";
 } else{
       echo "error uploading";
  }

 }

使用 imageCount 将图像总数发送到不同的变量中发布到服务器,但这每次都会引发上传错误。

When I POST some images to my server using:

ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url];
[request setShouldStreamPostDataFromDisk:YES];
[request setData:image withFileName:@"file(0)" andContentType:@"image/jpg" forKey:fileString];
[request setData:image withFileName:@"file(1)" andContentType:@"image/jpg" forKey:fileString];
[request setData:image withFileName:@"file(2)" andContentType:@"image/jpg" forKey:fileString];
[request startAsynchronous];

How do I catch this in a PHP script?

I was doing

for($i = 0; $i<$imageCount; $i++){

$target_path = "files/";

$target_path = $target_path . basename( $_FILES['file($i)']['name']); 

if(move_uploaded_file($_FILES['file($i)']['tmp_name'], $target_path)) {
  echo "Image: ".  basename( $_FILES['uploadedfile']['name']). 
" has been uploaded";
 } else{
       echo "error uploading";
  }

 }

with imageCount the total number of images being sent POSTed in a different variable to the server, but this throws me upload errors each time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

少女情怀诗 2024-12-20 00:54:47
echo $target_path;
$fileVar = "file($i)";
$target_path = $target_path.basename($_FILES[$fileVar]['name']);

我相信错误与该文件有关。

echo $target_path;
$fileVar = "file($i)";
$target_path = $target_path.basename($_FILES[$fileVar]['name']);

I believe the error is with that files.

他不在意 2024-12-20 00:54:47

解决方案:

for ($i = 0; $i<$imageCount; $i++){
$target_path = "files/".basename($_FILES['file('.$i.')']['name']); 

if(copy($_FILES['file('.$i.')']['tmp_name'], $target_path)) {
   echo "Image has been uploaded";
}else{
    echo "error uploading";
    print_r($_FILES) ;
 }
}

Solution:

for ($i = 0; $i<$imageCount; $i++){
$target_path = "files/".basename($_FILES['file('.$i.')']['name']); 

if(copy($_FILES['file('.$i.')']['tmp_name'], $target_path)) {
   echo "Image has been uploaded";
}else{
    echo "error uploading";
    print_r($_FILES) ;
 }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文