【发布时间】:2016-02-02 16:36:12
【问题描述】:
我正在尝试使用 cURL 在 POST 中发送原始二进制文件以及其他一些数据。 基本上,我是这样做的:
//Here i create the CURLFile
$cfile = new CURLFile($fullpath,'application/xml', $filename);
//Data to upload (including the file)
$data_upload = array('username' => $username,
'password' => $password,
'owner' => $owner,
'destination' => $pathpda,
'filename' => $filename,
'filedata' => $cfile);
//Upload
$ch_upload = curl_init($urlws.$e_upload);
curl_setopt($ch_upload, CURLOPT_POST,true);
curl_setopt($ch_upload, CURLOPT_POSTFIELDS, $data_upload);
curl_setopt($ch_upload, CURLOPT_RETURNTRANSFER, true);
$response_upload = curl_exec($ch_upload);
curl_close($ch_upload);
一切正常。除了现在我希望我的文件只是二进制数据而不是磁盘上的真实文件。另外,我需要在请求中发送其他数据! 有谁知道该怎么做?我在 Google 中查找,但我无法找到同时发送原始二进制文件和其他数据的方法。 谢谢!
更新 为了进一步澄清我的问题,我不需要只发送随机二进制数据,而是发送内容来自 ob_get_contents() 的文件(例如),因此它不是磁盘上的物理文件。如果我只是替换 CURLfile 以使用“filedata”变量发送二进制文件数据,它根本不起作用。 Web 服务无法识别该文件。也许有一种方法可以在不指向真实文件的情况下创建 CURLfile。
【问题讨论】:
-
您的问题是如何发送不是光盘上真实文件的数据?
-
我的问题是如何发送一个尚未保存在服务器磁盘上的文件,(例如,从数据库中检索的文件或 ob_get_contents() 的输出)与其他常用的发布数据一起使用卷曲。
-
根据
FILE这个词的定义,它存储在磁盘上的folder中,否则它只是内容。文件和文件系统只是数据存储方式的范例,您只想发送与发送用户名字符串没有什么不同的内容。 -
@BasvanStein - 你不知道你在说什么。
标签: php curl http-post binary-data raw-data