繁体   English   中英

使用PHP cURL将文件上传到远程服务器

[英]Upload File To Remote Server With PHP cURL

我想使用POST将文件从网站传输到该网站gulfup.com。

我的代码(包含一个没有上传文件的问题):

<?php

$the_file = "http://downloads.wordpress.org/plugin/wp-super-cache.1.2.zip";

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_URL, 'http://www.gulfup.com/index.php');
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
    'file_1_' => "$the_file"
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
if(curl_errno($ch)) {
    echo 'Error: ' . curl_error($ch);
}
else {
    echo $response;
}

?>

从pc上传的网站代码:

<form id="uploader" name="uploader" action="http://www.gulfup.com/index.php" method="post" enctype="multipart/form-data" onsubmit="form_submit();">
<div class="uploadfile"><input name="file_1_" id="file_1_" size="70" type="file"></div>
<br id="br_1_">
<div class="uploadfile"><input name="file_2_" id="file_2_" size="70" type="file"></div>
<br id="br_2_">
<div class="uploadfile"><input name="file_3_" id="file_3_" size="70" type="file"></div>
<br id="br_3_">
<div class="uploadfile"><input name="file_4_" id="file_4_" size="70" type="file"></div>
<br id="br_4_">
<div class="uploadfile"><input name="file_5_" id="file_5_" size="70" type="file"></div>
<br id="br_5_">
<div class="uploadfile"><input name="file_6_" id="file_6_" size="70" type="file"></div>
<br id="br_6_">
<div class="uploadfile"><input name="file_7_" id="file_7_" size="70" type="file"></div>
<br id="br_7_">
<div class="uploadfile"><input name="file_8_" id="file_8_" size="70" type="file"></div>
<br id="br_8_">
<div class="uploadfile"><input name="file_9_" id="file_9_" size="70" type="file"></div>
<br id="br_9_">
<div class="uploadfile"><input name="file_10_" id="file_10_" size="70" type="file"></div>
<br id="br_10_">
<br>

<span class="bn_up"><button type="submit" name="submitr" class="btn" id="submitr"><span>Upload</span></button></span>

<div class="clr"></div>
</form>

我的代码有什么问题?

好像是http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html,您忘记了帖子数组中的@(字符)

尝试编辑第一行

$the_file = "http://downloads.wordpress.org/plugin/wp-super-cache.1.2.zip";

$the_file = fetch_remote_file("http://downloads.wordpress.org/plugin/wp-super-cache.1.2.zip");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM