php 如何在邮递员 ReSTful Web 服务中发送多个文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28185300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to send multiple files in postman ReSTful web service?
提问by Harsimer
I am using ReSTful webservice. I am uploading multiple photos with one function (PHP).
我正在使用 ReSTful 网络服务。我正在使用一个功能(PHP)上传多张照片。
I have used $num_files = count($_FILES['myfile']['name'])
to count number of files that are to be uploaded but this always gives 1:
我曾经$num_files = count($_FILES['myfile']['name'])
计算过要上传的文件数,但这总是给 1:
When I print $_FILES['myfile']['name']
or $_FILES
it returns last image.
当我打印$_FILES['myfile']['name']
或$_FILES
返回最后一张图像时。
Am I suppose to do any setting to send multiple files at a time?
我是否应该进行任何设置以一次发送多个文件?
<?php
if($result=="success")
{
$num_files = count($_FILES['myfile']['name']);
Zend_Debug::dump($num_files);
die;
for( $i=0; $i < $num_files; $i++ )
{
$name = $_FILES["myfile"]["name"][$i];
$temp_path = $_FILES['myfile']['tmp_name'][$i];
$image_name = Helper_common::getUniqueNameForFile( $name );
echo $image_name;
die;
// Set the upload folder path
$target_path = $originalDirecory."/";
// Set upload image path
$image_upload_path = $target_path.$image_name;
move_uploaded_file($temp_path, $image_upload_path);
//if(move_uploaded_file($temp_path, $image_upload_path))
//{
// Set 800*800 popup thumbnail...
// Set popup directory...
$thumbnail_directory=$popUpDirectory."/";
// Set thumbnail name...
$thumb_name1=$thumbnail_directory.'thumbnail_'.$image_name;
// Set width and height of the thumbnail...
$thumb_width=800;
$thumb_height=800;
$thumb1=Helper_common::generateThumbnail($image_upload_path, $thumb_name1, $thumb_width, $thumb_height);
//if($thumb)
//{
// Set 435*333 thumbnail...
// Set thumbnail directory...
$thumbnail_directory=$wallDirecory."/";
// Set thumbnail name...
$thumb_name2=$thumbnail_directory.'thumbnail_'.$image_name;
// Set width and height of the thumbnail...
$thumb_width=435;
$thumb_height=435;
$thumb2=Helper_common::generateThumbnail($image_upload_path, $thumb_name2, $thumb_width, $thumb_height);
//if($thumb)
//{
// Set 176*176 thumbnail...
// Set thumbnail directory...
$thumbnail_directory=$galleryDirectory."/";
// Set thumbnail name...
$thumb_name3=$thumbnail_directory.'thumbnail_'.$image_name;
// Set width and height of the thumbnail...
$thumb_width=176;
$thumb_height=176;
$thumb_smart_resize_3 = Helper_ImageResizer::smart_resize_image($image_upload_path, NULL, $thumb_width, $thumb_height, false, $thumb_name3, false);
$thumb3=Helper_common::generateThumbnail($image_upload_path, $thumb_name3, $thumb_width, $thumb_height);
//if($thumb)
//{
$profile_thumb=$thumb3;
// Set 131*131 thumbnail...
// Set thumbnail directory....
$thumbnail_directory = $thumbnailsDirectory."/";
// Set thumbnail name....
$thumb_name4 = $thumbnail_directory.'thumbnail_'.$image_name;
$thumb_width=131;
$thumb_height=131;
$thumb_smart_resize_4=Helper_ImageResizer::smart_resize_image($image_upload_path, NULL, $thumb_width, $thumb_height, false, $thumb_name4, false);
$thumb4=Helper_common::generateThumbnail($image_upload_path, $thumb_name4, $thumb_width, $thumb_height);
}
回答by Harsimer
I got a solution. I need to make myfile an array like this: myfile[] :)
我得到了解决方案。我需要使 myfile 成为这样的数组:myfile[] :)
回答by Shihab Uddin
回答by Anees Hameed
回答by RahmanRezaee
Yeah,last version of postman made a bad update.
是的,邮递员的最新版本进行了错误的更新。
But, you can download the chrome extensions of postman and send multiple files with it, it still works there.
但是,您可以下载 postman 的 chrome 扩展并使用它发送多个文件,它仍然可以在那里工作。
Edit: I just checked now, they brought it back, but you have to reenter the key value for files if you made them with the chromium version.
编辑:我刚刚检查过,他们把它带回来了,但如果你用铬版本制作文件,你必须重新输入文件的键值。
But now it works fine.
但现在它工作正常。