4
A
回答
1
sender.php
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// true to return the transfer as a string of the return value
// of 'curl_exec' instead of outputting it directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_URL, 'http://localhost/test/curl/receiver.php');
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
'euro' => '@eurodance.pls',
'flush' => '@flush_next.png',
'first_name' => 'Vadim'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
print_r($response);
receiver.php
if(isset($_FILES)){
$temp_file_name = $_FILES['euro']['tmp_name'];
$original_file_name = $_FILES['euro']['name'];
// Find file extention
$ext = explode ('.', $original_file_name);
$ext = $ext [count ($ext) - 1];
// Remove the extention from the original file name
$file_name = str_replace ($ext, '', $original_file_name);
$new_name = '_'.$file_name . $ext;
//echo $file_name ." ". $ext;
if (move_uploaded_file ($temp_file_name, $new_name)) {
echo "success";
} else {
echo "error";
}
}
if(isset($_FILES)){
$temp_file_name = $_FILES['flush']['tmp_name'];
$original_file_name = $_FILES['flush']['name'];
// Find file extention
$ext = explode ('.', $original_file_name);
$ext = $ext [count ($ext) - 1];
// Remove the extention from the original file name
$file_name = str_replace ($ext, '', $original_file_name);
$new_name = '_'.$file_name . $ext;
//echo $file_name ." ". $ext;
if (move_uploaded_file ($temp_file_name, $new_name)) {
echo "success";
} else {
echo "error";
}
}
0
根據你給出的內容,使用cURL好像使用了錯誤的工具(即當你有一把錘子,每個問題都看起來像釘子),爲什麼不看SCP/SFTP甚至是rsync?不夠靈活。如果沒有,你必須擁有該文件的源服務器上,並開始捲曲請求文件(即通過HTTP)
2
大量可用資源,這裏有一對夫婦:
http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html
http://www.phpclasses.org/package/3753-PHP-Upload-files-via-HTTP-POST-using-Curl.html
從未使用過它們,也沒有必要。但應該幫助你開始。
相關問題
- 1. Highchart使用cURL保存圖表圖像
- 2. JAVA:Chunked Tranfer Over Jersey
- 3. 使用curl請求php圖像上傳
- 4. 使用PHP curl獲取/保存圖像
- 5. 使用PHP cURL下載多個圖像
- 6. 使用curl從SSL下載圖像?
- 7. 使用cURL圖像下載到ZipArchive
- 8. 使用curl檢索圖像-php(issue)
- 9. 用cURL抓取圖像php
- 10. 使用CURL保存圖像,有時它保存空白圖像
- 11. CURL PHP發送圖像
- 12. 使用cURL通過代理獲取谷歌圖表圖像
- 13. 用PHP和cURL上傳圖像
- 14. 用cURL獲取葡萄樹圖像
- 15. 用PHP Curl上傳多個圖像
- 16. 使用PHP和cURL調整遠程圖像的大小
- 17. 如何使用PHP cURL發送正確的Content-Type圖像?
- 18. 使用cURL和sed輸出基於布爾狀態的圖像
- 19. 無法下載URL中帶有空格的圖像使用cURL
- 20. 使用curl解析XML,獲取圖像的URL並下載它
- 21. 如何在使用CURL時禁用加載圖像?
- 22. 使用Google圖像檢索圖像API和CURL始終使用相同的鏈接
- 23. 如何使用curl上傳一個使用「Content-Type:multipart/related」的圖像文件
- 24. 使用PHP cURL檢索圖像時拒絕連接
- 25. 使用cURL從外部URL下載圖像
- 26. 使用cURL獲取遠程圖像然後重新採樣
- 27. PHP - 使用CURL將圖像文件上傳到其他域
- 28. 使用curl和PHP從PHP URL保存圖像
- 29. 使用curl與node.js下載圖像並將其轉換爲base64
- 30. 使用cURL多線程圖像下載,PHP