简体   繁体   English

使用PHP CURL上传文件

[英]Uploading a file using PHP CURL

I have a front end php application that is connected to an API. 我有一个连接到API的前端php应用程序。 The application talks to the API through PHP curl as that is the only mode of communication. 该应用程序通过PHP curl与API进行通信,因为这是唯一的通信方式。

I need to upload files to the server, these files are taken from the browser and sent to the server. 我需要将文件上传到服务器,这些文件是从浏览器中获取并发送到服务器的。

What would be the best way to send a multi part file to the server using curl. 使用curl将多部分文件发送到服务器的最佳方法是什么。

Currently i am sending the file using $_POST , but i dont think that is recommended. 目前,我正在使用$ _POST发送文件,但是我不建议这样做。

If your using curl POST then you can just add the file to the POST with @ 如果您使用curl POST,则只需使用@将文件添加到POST

// same as <input type="file" name="fileField">
$post = array(
    "fileField"=>"@/path/to/file.jpg",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 

There are plenty of results on google Google有很多结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM