我从来没有做过卷曲,所以需要一些帮助。我已经尝试通过示例来解决这个问题,但是我无法理解!
我有一个curl命令,可以从linux(ubuntu)命令行成功运行,该命令行通过api将文件放入Wiki。
我需要将此curl命令合并到我正在构建的PHP脚本中。
如何转换curl命令,使其在PHP脚本中起作用?
curl -b cookie.txt -X PUT \ --data-binary "@test.png" \ -H "Content-Type: image/png" \ "http://hostname/@api/deki/pages/=TestPage/files/=test.png" \ -0
cookie.txt包含身份验证,但是我不会在脚本中将其以明文形式出现,因为这将仅由我运行。
@ test.png必须是$ filename之类的变量
http:// hostname / @ api / deki / pages / = TestPage / files / =必须是变量,例如$ pageurl
谢谢你的帮助。
起点:
<?php $pageurl = "http://hostname/@api/deki/pages/=TestPage/files/="; $filename = "test.png"; $theurl = $pageurl . $filename; $ch = curl_init($theurl); curl_setopt($ch, CURLOPT_COOKIE, ...); // -b curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // -X curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: image/png']); // -H curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // -0 ... ?>