CLI卷曲PHP卷曲上传文件
问题描述:
我试图设置PHP curl库呼吁采取:CLI卷曲PHP卷曲上传文件
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
(这是互联网档案馆的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;
错误:你的POST请求的MalformedPOSTRequestThe身体不是很好,形成多/表单data.bucket必须在DNS hostnameXXXXXXXXXX
我能代替我自己的价值观到CLI卷曲声明&上传没有问题;我似乎无法得到正确的PHP卷曲
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);
您的'curl'命令是否正常工作? –
这很奇怪 - 我已经添加了CURLOPT_UPLOAD,CURLOPT_INFILE,CURLOPT_INFILESIZE,它似乎已经工作了一次,但我无法再让ti再次工作。很确定在这一点上,它是最后一天的疲惫,所以要休息一下,再看一遍 感谢迄今 - 你的--libcurl向我展示了方式! – jmadsen