php教程 curl模仿ftp文件上传代码
好了下面封闭成类了
classcurl_ftp
{
private $ftpname; //ftp用户名
private $ftppaw; //ftp密码
private $urlftp; //ftp地址
private $filename; // public __construct($ name、$ password、$ ftp)
{
$ this-> ftpname = $ name; $ftp;
// $this->filename = $filename;
}
パブリック関数 getftp()
{
if (isset($_post['submit']))
{
if (!empty( $ _files['upload']['name']))
{
$ch =curl_init();
$this->filename = $_files['upload']['tmp_name'];
$fp = fオープン( $this->ファイル名, 'r');
curl_setopt($ch,curlopt_url, $this->ftp.$this->ファイル名);
curl_setopt($ch,curlopt_userpwd, "$name:password") ;
curl_setopt($ch,curlopt_upload, 1);
curl_setopt($ch,curlopt_infile, $fp);
curl_setopt($ch,curlopt_infilesize, filesize($this->filename));
curl_exec ($ch);
$error_no =curl_errno($ch);
curl_close ($ch);
if ($error_no == 0)
{
$error = '文件上传成功';
}
else
{
$error = '文件上传失败';
}
else
{
$error = '未选择文件';
}
}
}
}