PHP接收通過CURL傳送的二進位(二進制)檔案 (CURL 上傳二進制檔到 PHP WEB SERVER/簡易檔案伺服器)

PHP接收通過CURL傳送的二進位(二進制)檔案 (CURL 上傳二進制檔到 PHP WEB SERVER/簡易檔案伺服器)

PHP接收通過CURL傳送的二進位(二進制)檔案 (CURL 上傳二進制檔到 PHP WEB SERVER/簡易檔案伺服器)


資料來源: https://www.796t.com/post/ZDlwdWk=.html

Code:

<?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);
}

shell(bat): 

curl --request POST  --data-binary "@binary.jpg"  http://example.com/uploader.php

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *