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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:43:38  来源:igfitidea点击:

How to send multiple files in postman ReSTful web service?

phpweb-servicesrestfile-uploadpostman

提问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:

Image

图片

When I print $_FILES['myfile']['name']or $_FILESit 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

You need to add a square bracket[]sign to the parameter. Look at the following image. I add file[]to upload multiple images from the postman.

您需要在参数中添加方括号[]符号。看下图。我添加file[]以从邮递员上传多个图像。

enter image description here

在此处输入图片说明

回答by Anees Hameed

You can simple add multiple lines with same key and postman converts them to array. No need to add [] as suffix to key.

您可以简单地添加具有相同键的多行,邮递员将它们转换为数组。无需添加 [] 作为键的后缀。

Request

要求

enter image description here

在此处输入图片说明

Response

回复

enter image description here

在此处输入图片说明

If you have an array objectsthat need to passed then follow below pattern

如果您有一个需要传递的数组对象,请遵循以下模式

enter image description here

在此处输入图片说明

回答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.

但现在它工作正常。