Home > Backend Development > PHP Tutorial > CURL 模拟FTP下传文件

CURL 模拟FTP下传文件

WBOY
Release: 2016-06-13 13:18:12
Original
993 people have browsed it

CURL 模拟FTP上传文件
// CURL 模拟FTP上传文件 
// 作者: m
// QQ: 251171960
$url = "ftp://61.54.28.3/".mt_rand(99,999).".txt";
$file = "20090829.txt";
$fp = fopen ($file, "r");
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1); //有意外发生则报道
curl_setopt($ch, CURLOPT_USERPWD, 'ffff:****'); //FTP登陆账号密码,模拟登陆
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_PUT, 1); //用HTTP上传一个文件
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //不输出
curl_setopt($ch, CURLOPT_INFILE, $fp); //要上传的文件
curl_setopt($ch, CURLOPT_INFILESIZE,filesize($localfile)); //上传文件大小
$http_result = curl_exec($ch); //执行
$error = curl_error($ch); 
curl_close($ch);
fclose($fp);
if (!$error) 
{
print "成功";
}
?>

------解决方案--------------------
随便看看 有所收获 谢啦!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template