网上一堆代码,没有一个真正实现curl传图片成功过的,这儿,我来个成功的,超级简单,扩展性强【广告一下】
上传端:
接收端:
上传端:
<?php
function upload_curl_pic()
{
$url = 'http://localhost//5-5-5//uploadfile.php'; //target url
$file = 'c:/21.jpg'; //要上传的文件
$fields['f'] = '@'.$file;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields );
curl_exec( $ch );
if ($error = curl_error($ch) ) {
die($error);
}
curl_close($ch);
}
upload_curl_pic();//可以扩展把图片地址传到函数中
?>
function upload_curl_pic()
{
$url = 'http://localhost//5-5-5//uploadfile.php'; //target url
$file = 'c:/21.jpg'; //要上传的文件
$fields['f'] = '@'.$file;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields );
curl_exec( $ch );
if ($error = curl_error($ch) ) {
die($error);
}
curl_close($ch);
}
upload_curl_pic();//可以扩展把图片地址传到函数中
?>
接收端:
<?php
$uploaddir = 'E:\\wwwroot\\www\\htdocs\\5-5-5\\pic_all_here\\';
$uploadfile = $uploaddir . $_FILES['f']['name'];
if (move_uploaded_file($_FILES['f']['tmp_name'], $uploadfile))
{
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
echo 'Here is some more debugging info:';
}
?>
$uploaddir = 'E:\\wwwroot\\www\\htdocs\\5-5-5\\pic_all_here\\';
$uploadfile = $uploaddir . $_FILES['f']['name'];
if (move_uploaded_file($_FILES['f']['tmp_name'], $uploadfile))
{
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
echo 'Here is some more debugging info:';
}
?>