亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

透過(guò) Curl PHP 表單資料將伺服器儲(chǔ)存的 PDF 檔案?jìng)魉偷搅硪慌_(tái)伺服器
P粉521748211
P粉521748211 2023-08-31 12:44:11
0
1
701
<p>我正在嘗試透過(guò) Curl PHP Form Data 方法將儲(chǔ)存在我的伺服器上的 PHP 檔案?jìng)魉偷搅硪慌_(tái)伺服器。 </p> <p>通常,這是透過(guò)提交表單並上傳文件並將相同的文件作為表單資料發(fā)送到Curl PHP 端點(diǎn)來(lái)完成的,但在這種情況下,我的伺服器上已經(jīng)有了該文件,並且我陷入如何取得的部分該檔案並建立其表單資料數(shù)組並將API Url 作為post 方法傳送。 </p> <p>下面是我正在嘗試的某種程式。其中之一是創(chuàng)建一個(gè) tmp 檔案並在其中儲(chǔ)存數(shù)據(jù),並將該數(shù)據(jù)從 tmp 位置發(fā)送到curl 表單數(shù)據(jù)。 </p> <p>$source = file_get_contents("https://url/employee_manual3.pdf");</p> <pre class="brush:php;toolbar:false;">$tempFile = tempnam(sys_get_temp_dir(), 'File_'); rename($tempFile, $tempFile .= '.pdf'); file_put_contents($tempFile, $source); // var_dump($tempFile); // exit; // $post = array( // "uploadedFile" => "@" . $tempFile, //"@".$tempFile.";type=application/pdf", // ); // var_dump(file_get_contents($tempFile)); // var_dump(new CURLFILE($tempFile)); // exit; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://API_URL', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array('file' => new CURLFILE($tempFile)), CURLOPT_HTTPHEADER => array( 'Authorization: Bearer API TOKEN HAI MERA', 'Content-Type: multipart/form-data', 'Cookie: MAIN NAHI BATAUNGA' ), )); $response = curl_exec($curl); curl_close($curl); echo $response;</pre> <pre class="brush:php;toolbar:false;"></pre></p>
P粉521748211
P粉521748211

全部回覆(1)
P粉321676640

嗨,您可以查看下面的答案,了解我是如何成功實(shí)現(xiàn)這一目標(biāo)的。

// $source = file_get_contents("https://URL/assets/email_images/employee_manual3.pdf");

    $file_path = __DIR__.'/../../../assets/email_images/employee_manual3.pdf';

    // var_dump(__DIR__.'/../../../assets/email_images/employee_manual3.pdf');
    // exit;

    // var_dump(new CURLFILE($file_path, 'application/pdf', 'file'));
    // exit;

    $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => 'API URL',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS => array('file' => new CURLFILE($file_path, 'application/pdf', 'file')),
    ));

    $response = curl_exec($curl);

    curl_close($curl);
    echo $response;
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板