PHP Tutorial Curl mimics ftp file upload code
if (Isset ($_post[' submit ')) {
if (!empty ($_files[' upload ' [' name '])) {
$ch = Curl_init ();
$localfile = $_files[' upload ' [' tmp_name '];
$fp = fopen ($localfile, ' R ');
curl_setopt ($ch, Curlopt_url, ' ftp://ftp_login:password@ftp.domain.com/'. $_files[' upload ' [' name ']);
curl_setopt ($ch, curlopt_upload, 1);
curl_setopt ($ch, Curlopt_infile, $fp);
curl_setopt ($ch, Curlopt_infilesize, FileSize ($localfile));
Curl_exec ($ch);
$error _no = Curl_errno ($ch);
Curl_close ($ch);
if ($error _no = = 0) {
$error = ' file uploaded succesfully. ';
} else {
$error = ' File upload error. ';
}
} else {
$error = ' Please select a file. ';
}
}
?>
Okay, it's closed down into classes.
Class Curl_ftp
{
Private $ftpname; FTP User Name
Private $ftppaw; FTP password
Private $urlftp; FTP address
Private $filename; Filename
Public __construct ($name, $password, $ftp)
{
$this->ftpname = $name;
$this->ftppaw = $password;
$this->urlftp = $ftp;
$this->filename = $filename;
}
Public Function getftp ()
{
if (Isset ($_post[' submit '))
{
if (!empty ($_files[' upload ' [' name ']))
{
$ch = Curl_init ();
$this->filename = $_files[' upload ' [' tmp_name '];
$fp = fopen ($this->filename, ' R ');
curl_setopt ($ch, Curlopt_url, $this->ftp $this->filename);
curl_setopt ($ch, Curlopt_userpwd, "$name:p assword");
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 = ' File upload succeeded ';
}
Else
{
$error = ' File upload failed ';
}
}
Else
{
$error = ' no file selected ';
}
}
}
}
http://www.bkjia.com/PHPjc/444823.html www.bkjia.com true http://www.bkjia.com/PHPjc/444823.html techarticle PHP Tutorial Curl mimics ftp File upload code body form action=curlupload.php method=post enctype=multipart/form-data Div label for= Uploadselect File/label input name=upload type=file ...