PHP implements ftp file upload example ,. PHP implements ftp file upload example. FTP upload is a common and important application skill for PHP implementation. today I will share with you a simple example of PHP for FTP file upload. You want PHP to implement an ftp file upload example,
FTP upload is a common and important application technique for PHP implementation. today, I will share with you a simple example of PHP to implement FTP file upload. I hope this will help you learn PHP.
The main code is as follows:
Function make_directory ($ ftp_stream, $ dir) {// if directory already exists or can be immediately created return true if ($ this-> ftp_is_dir ($ ftp_stream, $ dir) | @ ftp_mkdir ($ ftp_stream, $ dir) return true; // otherwise recursively try to make the directory if (! $ This-> make_directory ($ ftp_stream, dirname ($ dir) return false; // final step to create the directory return ftp_mkdir ($ ftp_stream, $ dir );} function ftp_is_dir ($ ftp_stream, $ dir) {// get current directory $ original_directory = ftp_pwd ($ ftp_stream ); // test if you can change directory to $ dir // suppress errors in case $ dir is not a file or not a directory if (@ ftp_chdir ($ ftp_stream, $ dir )) {// If it is a directory, then change the directory back to the original directory ftp_chdir ($ ftp_stream, $ original_directory); return true;} else {return false ;}} $ conn = ftp_connect ("ftp address") or die ("cocould not connect"); ftp_login ($ conn, "ftpname", "password "); // use ftp to create the directory make_directory ($ conn, $ path); // use ftp to select the directory ftp_chdir ($ conn, $ path ); // Start to upload if (ftp_put ($ conn, $ info [0] ['savename'], getcwd (). $ upload-> savePath. $ info [0] ['savename'], FTP_BINARY) {unlink (getcwd (). $ upload-> savePath. $ info [0] ['savename']);} ftp_close ($ conn); // pay attention to the ftp permission settings on the upload end
If you are interested, you can test and run the code or rewrite the code described in this article to improve the code functions.
FTP upload is a common and important application technique for PHP implementation. today I will share with you a simple example of using PHP to upload files over FTP. Hope...