我想要做的是保存從另一個服務器通過CURL發送的二進制文件。接收通過CURL發送的二進制文件
的PHP上傳我的是:
<?php
define("UPLOAD_DIR", "/tmp/");
if (!empty($_FILES["myFile"])) {
$myFile = $_FILES["myFile"];
if ($myFile["error"] !== UPLOAD_ERR_OK) {
echo "<p>An error occurred.</p>";
exit;
}
// ensure a safe filename
$name = preg_replace("/[^A-Z0-9._-]/i", "_", $myFile["name"]);
// don't overwrite an existing file
$i = 0;
$parts = pathinfo($name);
while (file_exists(UPLOAD_DIR . $name)) {
$i++;
$name = $parts["filename"] . "-" . $i . "." . $parts["extension"];
}
// preserve file from temporary directory
$success = move_uploaded_file($myFile["tmp_name"],
UPLOAD_DIR . $name);
if (!$success) {
echo "<p>Unable to save file.</p>";
exit;
}
// set proper permissions on the new file
chmod(UPLOAD_DIR . $name, 0644);
}
所以我有這個在我的網站這樣:
example.com/uploader.php
在服務器2號,我跑命令:
curl --request POST --data-binary "@binary.jpg" http://example.com/uploader.php
然後我檢查我/ tmp /文件夾的文件名爲binary.jpg,但它不是那裏,這裏有什麼問題?
謝謝。
這是http://stackoverflow.com/questions/12667797/using-curl-to-upload-post-data-with-檔案? –
@NicolasBouvrette第 – bobb
你可以嘗試在該帖子中提出的curl命令來查看你的上傳器是否工作? –