当我使用以下方法将一些图像发布到我的服务器时:
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将发送的图像总数以不同的变量发送到服务器,但每次都会引发上传错误。
答案 0 :(得分:0)
echo $target_path;
$fileVar = "file($i)";
$target_path = $target_path.basename($_FILES[$fileVar]['name']);
我认为该错误与该文件有关。
答案 1 :(得分:0)
解决方案:
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) ;
}
}