使用PHP CURL上传文件 [英] Uploading a file using PHP CURL

查看:178
本文介绍了使用PHP CURL上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到API的前端PHP应用程序。应用程序通过PHP curl与API通信,因为这是唯一的通信模式。

I have a front end php application that is connected to an API. The application talks to the API through PHP curl as that is the only mode of communication.

我需要将文件上传到服务器,这些文件是从浏览器中获取的,发送到服务器。

I need to upload files to the server, these files are taken from the browser and sent to the server.

使用curl将多部分文件发送到服务器的最佳方法是什么。

What would be the best way to send a multi part file to the server using curl.

目前我使用$ _POST发送文件,但我不认为这是推荐。

Currently i am sending the file using $_POST , but i dont think that is recommended.

推荐答案

如果您使用curl POST,那么您只需使用@

If your using curl POST then you can just add the file to the POST with @

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

google

这篇关于使用PHP CURL上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆