使用 curl 命令行将多个文件上传到 php 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11599957/
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 00:50:48  来源:igfitidea点击:

upload multiple files to php server using curl command line

phpcurl

提问by sapatos

I need to upload multiple files to a server using the curl command line utility. for a single file I have no problem using:

我需要使用 curl 命令行实用程序将多个文件上传到服务器。对于单个文件,我使用没有问题:

curl -F "[email protected]"   http://localhost:8888/web/Upload.php

how would I do this with more than one file so that the php variable $_FILES["image"]["error"] would return an array?

我将如何使用多个文件执行此操作,以便 php 变量 $_FILES["image"]["error"] 将返回一个数组?

I've tried

我试过了

curl -F "[email protected]" -F "[email protected]"  http://localhost:8888/web/Upload.php
curl -F "[email protected],[email protected]"  http://localhost:8888/web/Upload.php

but these are a stab in the dark.

但这些都是暗中刺伤。

回答by complex857

The trick is to name the file uploading parameters unique.

诀窍是将文件上传参数命名为唯一的。

curl -F "[email protected]" -F "[email protected]"  http://localhost:8888/web/Upload.php

This will show up in the $_FILESsuperglobal as $_FILES['image']and $_FILES['image2'].

这将在$_FILES超全局变量中显示为$_FILES['image']and $_FILES['image2']

To make the files grouped under one $_FILESindex you need to name the parameters as arrays:

要将文件分组到一个$_FILES索引下,您需要将参数命名为数组:

curl -F "image[][email protected]" -F "image[][email protected]"  http://localhost:8888/web/Upload.php