使用 curl 命令行将多个文件上传到 php 服务器 [英] upload multiple files to php server using curl command line
问题描述
我需要使用 curl 命令行实用程序将多个文件上传到服务器.对于单个文件,我使用没有问题:
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 -F "image=@file1.gif" http://localhost:8888/web/Upload.php
我将如何处理多个文件,以便 php 变量 $_FILES["image"]["error"] 返回一个数组?
how would I do this with more than one file so that the php variable $_FILES["image"]["error"] would return an array?
我试过了
curl -F "image=@file1.gif" -F "image=@file2.gif" http://localhost:8888/web/Upload.php
curl -F "image=@file1.gif,image=@file2.gif" http://localhost:8888/web/Upload.php
但这些都是暗中刺伤.
推荐答案
诀窍是命名文件上传参数唯一.
The trick is to name the file uploading parameters unique.
curl -F "image=@file1.gif" -F "image2=@file2.gif" http://localhost:8888/web/Upload.php
这将在 $_FILES
超全局变量中显示为 $_FILES['image']
和 $_FILES['image2']
.
This will show up in the $_FILES
superglobal as $_FILES['image']
and $_FILES['image2']
.
要将文件分组到一个 $_FILES
索引下,您需要将参数命名为数组:
To make the files grouped under one $_FILES
index you need to name the parameters as arrays:
curl -F "image[]=@file1.gif" -F "image[]=@file2.gif" http://localhost:8888/web/Upload.php
这篇关于使用 curl 命令行将多个文件上传到 php 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!