第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用 cURL 將 Pdf 文件上傳到另一個(gè)網(wǎng)站

使用 cURL 將 Pdf 文件上傳到另一個(gè)網(wǎng)站

PHP
德瑪西亞99 2023-04-28 14:44:31
特別是與這個(gè)特定的線程有關(guān)使用 php 將文件上傳到網(wǎng)站我想在 PHP 上使用 cURL 來(lái)實(shí)現(xiàn)這個(gè)。我該如何設(shè)置?以下是我嘗試過(guò)的。請(qǐng)注意,我只是通過(guò)添加我嘗試過(guò)的代碼來(lái)編輯它。<?php if(isset($_POST["submit"])){ $errors= array();// $name = $_FILES['fileToUpload']['name'];  $size = $_FILES['fileToUpload']['size'];  $type = $_FILES['fileToUpload']['type'];  $tmp_name = $_FILES['fileToUpload']['tmp_name'];  $upload_ok =1; $file_ext=strtolower(end(explode('.',$_FILES['fileToUpload']  ['name'])));// $extensions= array("pdf","jpeg","jpg","png"); $jj = file_get_contents($_FILES['fileToUpload']['tmp_name']); $mj = base64_encode($jj); if(in_array($file_ext,$extensions)=== false){  $errors[]="vvvvv."; }  if($size >= xxx){  $errors[]='xxx;' } if(empty($errors)==true){  echo  "Success </br>";  $request  = "xxxxxxxxx";  $headers = array(    "Authorization: Bearer xxxxxx",     "Content-type => multipart/form-data",     "Accept:application/json",  );  $data = [     'voucher_data' => 'base64_encode($tmp_name)',   'callback_url' => 'xxxxxxxxx'  ];  $curl = curl_init();  curl_setopt_array($curl, array(    CURLOPT_URL => "xxxxxxxxxx",    CURLOPT_RETURNTRANSFER => true,    CURLOPT_ENCODING => "",    CURLOPT_MAXREDIRS => 10,    CURLOPT_TIMEOUT => 30,    CURLOPT_FOLLOWLOCATION => true,    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,    CURLOPT_CUSTOMREQUEST => "POST",    CURLOPT_POSTFIELDS =>  $data,    CURLOPT_HTTPHEADER => $headers  ));  $response = curl_exec($curl);  curl_close($curl);  var_dump($response);  }else{  print_r($errors);  }?>我嘗試按照下面的建議使用 curl_file_create($mj) 但在 var_dump 上...它說(shuō) bool(false)
查看完整描述

2 回答

?
海綿寶寶撒

TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個(gè)贊

好吧,在嘗試了很多不同的方法之后,我直接將這個(gè)值傳遞給了 post 字段,而不是將它用作數(shù)組

CURLOPT_POSTFIELDS => “foo=$mj&callbackurl=url”,

它奏效了。這就是我被困的地方。我用另一種方式做了,但沒(méi)有用。每種情況都是獨(dú)一無(wú)二的。有人可能也需要這個(gè)。


查看完整回答
反對(duì) 回復(fù) 2023-04-28
?
夢(mèng)里花落0921

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超6個(gè)贊

我看到您想發(fā)出一個(gè)請(qǐng)求,將文件上傳到您自己以外的另一臺(tái)服務(wù)器。


在 PHP 5.5 之后,有一個(gè)名為 的函數(shù)curl_file_create,顧名思義,它用于上傳文件。


$post = array (

    'extra_info' => '123456', // If required.. like user_id for avatar

    'file_contents' => curl_file_create ('path/to/file');

);


$ch = curl_init ($url);

curl_setopt ($ch, CURLOPT_POST, 1);

curl_setopt ($ch, CURLOPT_POSTFIELDS, $post);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

$result=curl_exec ($ch);

curl_close ($ch); 

如果您不想使用它,那么有一個(gè)非常簡(jiǎn)單的方法:


$args = [];


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_POST, 1);


$args['file'] = '@/path/to/file';

curl_setopt($ch, CURLOPT_POSTFIELDS, $args);

curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);

curl_close ($ch); 


查看完整回答
反對(duì) 回復(fù) 2023-04-28
  • 2 回答
  • 0 關(guān)注
  • 257 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)