【发布时间】:2020-02-20 12:39:33
【问题描述】:
您好我正在尝试在 php Curl 操作中发送多个文件。我正在使用 PHP7.2 并尝试在同一密钥下发送 15 张图像。 如果我试图只发送 1 个文件,它的工作就很好。
$post["image"] = new \CurlFile('image_full_path.png', 'image/png', 'file.png');
但是当我尝试放置多个文件时,它不再工作了。
已经试过了 $post["image[0]"] = new \CurlFile('image_full_path.png', 'image/png', 'file.png');
还有
$post["image_0"] = new \CurlFile('image_full_path.png', 'image/png', 'file.png');
不工作
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"url");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
$path = '/var/www/download/download.pdf';
file_put_contents($path, $response);
echo $response;
【问题讨论】:
-
$post["image"][]怎么样?有人有suggested it before。
标签: laravel curl php-curl php-7.2