Phpcurl imitates the ftp file upload code. Php Tutorial curl imitating ftp file upload code bodyformactioncurlupload. phpmethodpostenctypemultipartform-datadivlabelforuploadselectfilelabelinputnameuploadtypefile php Tutorial curl imitating 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, the following is closed into a class.
Class curl_ftp
{
Private $ ftpname; // ftp user name
Private $ ftppaw; // ftp password
Private $ urlftp; // ftp address
Private $ filename; // file name
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: 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 = 'File uploaded successfully ';
}
Else
{
$ Error = 'File Upload failed ';
}
}
Else
{
$ Error = 'file not Selected ';
}
}
}
}
Curl imitates the ftp file upload code body form action = curlupload. php method = post enctype = multipart/form-data p label for = uploadselect file/label input name = upload type = file...