An ftp upload class, similar to an online example, is very simple and suitable for reference by new users. 1. file Upload ftp. class. php
FtpUrl = $ ftpUrl;} if ($ ftpUser) {$ this-> ftpUser = $ ftpUser;} if ($ ftpPass) {$ this-> ftpPass = $ ftpPass ;} if ($ ftpUrl) {$ this-> ftpDir = $ ftpDir;} if ($ this-> ftpR = ftp_connect ($ this-> ftpUrl, 21 )) {if (ftp_login ($ this-> ftpR, $ this-> ftpUser, $ this-> ftpPass) {if (! Empty ($ this-> ftpDir) {ftp_chdir ($ this-> ftpR, $ this-> ftpDir);} ftp_pasv ($ this-> ftpR, true ); // R enables passive mode; $ status = 1;} else {$ status = 3 ;}} else {$ status = 2 ;}// R switches the directory; function cd ($ dir) {return ftp_chdir ($ this-> ftpR, $ dir);} // R returns the current path strength; function pwd () {return ftp_pwd ($ this-> ftpR);} // R creates the directory function mkdir ($ directory) {return ftp_mkdir ($ this-> ftpR, $ directory );} // R deletes the function rmdi directory. R ($ directory) {return ftp_rmdir ($ this-> ftpR, $ directory);} // R upload a file; function put ($ localFile, $ remoteFile = '') {if ($ remoteFile = '') {$ remoteFile = end (explode ('/', $ localFile);} $ res = ftp_nb_put ($ this-> ftpR, $ remoteFile, $ localFile, FTP_BINARY); while ($ res = FTP_MOREDATA) {$ res = ftp_nb_continue ($ this-> ftpR);} if ($ res = FTP_FINISHED) {return true;} elseif ($ res = FTP_FAILED) {r Eturn false ;}}// R download file; function get ($ remoteFile, $ localFile = '') {if ($ localFile = '') {$ localFile = end (explode ('/', $ remoteFile);} if (ftp_get ($ this-> ftpR, $ localFile, $ remoteFile, FTP_BINARY )) {$ flag = true;} else {$ flag = false;} return $ flag;} // R file size; function size ($ file) {return ftp_size ($ this-> ftpR, $ file);} // whether the R file exists; function isFile ($ file) {if ($ this-> size ($ file)> = 0) {Return true;} else {return false ;}// R file Time function fileTime ($ file) {return ftp_mdtm ($ this-> ftpR, $ file );} // R delete the file; function unlink ($ file) {return ftp_delete ($ this-> ftpR, $ file );} function nlist ($ dir = '/service/resource/') {return ftp_nlist ($ this-> ftpR, $ dir);} // R close the connection; function bye () {return ftp_close ($ this-> ftpR) ;}}?> 2. call example uplaod. php
Put ($ localfile, $ remotefile); // FTP uploads the source image to the remote server $ ftp-> bye (); // closes the FTP connection unlink ($ workDir. "/". $ img_name) or die ("Cannot delete uploaded file from working directory -- manual deletion recommended"); if (! $ Ftpput) {return false;} else {return $ img_path. '/'. $ img_name;}?> |