很难说这里问的是什么。这个问题是模棱两可的,模糊的,不完整的,过于宽泛的,或者修辞上的,不能以目前的形式合理地回答。寻求帮助澄清这个问题,以便它可以重新打开,
访问帮助中心
..。
七年前就关门了。
我想知道如何上传文件使用cURL或任何其他在PHP。我在谷歌上搜索了很多次,但都没有结果。
换句话说,用户在表单上看到一个文件上传按钮,表单被发布到我的php脚本,然后我的php脚本需要重新发布到另一个脚本(例如在另一个服务器上)。
我有这个代码来接收文件并上传它
代码:
echo"".$_FILES['userfile']."";
$uploaddir = './';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if ( isset($_FILES["userfile"]) ) {
echo 'Uploaded';
if (move_uploaded_file
($_FILES["userfile"]["tmp_name"], $uploadfile))
echo $uploadfile;
else echo 'Failed';
}
我希望代码将文件发送到接收方文件。
发布于 2013-03-04 19:46:10
使用:
if (function_exists('curl_file_create')) { // php 5.5+
$cFile = curl_file_create($file_name_with_full_path);
} else { //
$cFile = '@' . realpath($file_name_with_full_path);
}
$post = array('extra_info' => '123456','file_contents'=> $cFile);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
您还可以参考:
http://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/
PHP 5.5+的重要提示:
现在我们应该使用
https://wiki.php.net/rfc/curl-file-upload
但是,如果您仍然希望使用这种不推荐使用的方法,则需要设置
https://stackoverflow.com/questions/15200632
复制相似问题