簡體   English   中英

cli curl到php curl上傳文件

[英]cli curl to php curl for uploading file

我正在嘗試將php curl庫調用設置為:

curl --location \
     --header "authorization: LOW $accesskey:$secret" \
     --upload-file /home/samuel/public_html/intro-to-k.pdf \
     http://s3.us.archive.org/sam-s3-test-08/demo-intro-to-k.pdf

(這是針對Internet存檔的api: http : //archive.org/help/abouts3.txt

當前位於Windows 7開發人員盒中,但將移至Ubuntu

我努力了:

        $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('authorization: LOW XXXX:XXXXX'));
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_URL, 'http://s3.us.archive.org/a_tested_working_dir/the_file_ane_and_ext' );
    $post_array = array(
        "upload-file"=>file_get_contents($absolute_path_to_my_file)
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array);
    $response = curl_exec($ch);
    echo $response;

錯誤:格式錯誤的POSTRequest您的POST請求的正文格式不正確的multipart /form-data。bucket必須位於dns主機名XXXXXXXXXX中

我可以將自己的值替換為cli curl語句並上傳而不會出現問題; 我只是似乎無法使php curl正確

TIA!


--libcurl轉儲產生:

CURLcode ret;
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_INFILESIZE_LARGE, (curl_off_t)64d);
curl_easy_setopt(hnd, CURLOPT_URL, "http://s3.us.archive.org/jeffs_test_1301_librivox/test-francesbaird3.mp3");
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1);
curl_easy_setopt(hnd, CURLOPT_UPLOAD, 1);
curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.21.1 (i686-pc-mingw32) libcurl/7.21.1 OpenSSL/0.9.8r zlib/1.2.3");
curl_easy_setopt(hnd, CURLOPT_CAINFO, "C:\Program Files\Git\bin\curl-ca-bundle.crt");
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 1);
curl_easy_setopt(hnd, CURLOPT_SSH_KNOWNHOSTS, "c:/Users/JMadsen/_ssh/known_hosts");
curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50);
ret = curl_easy_perform(hnd);
curl_easy_cleanup(hnd);

我認為可能是ssl驗證,但只是嘗試將其設置為false且未更改

上傳文件的發布字段初始化錯誤。 您不需要傳遞文件的內容。 只需使用@前綴傳遞文件的路徑。

$post_array = array(
    "upload-file"=>'@'. $absolute_path_to_my_file
);

根據--libcurl轉儲,也添加以下選項。

curl_setopt($ch, CURLOPT_NOPROGRESS, 1);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "curl/7.21.1 (i686-pc-mingw32) libcurl/7.21.1 OpenSSL/0.9.8r zlib/1.2.3");
curl_setopt($ch, CURLOPT_CAINFO, "C:\Program Files\Git\bin\curl-ca-bundle.crt");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSH_KNOWNHOSTS, "c:/Users/JMadsen/_ssh/known_hosts");
curl_setopt($ch, CURLOPT_MAXREDIRS, 50);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM