PHP Implementation FTP upload file example,
FTP upload is a common and very important application of PHP implementation skills, today to share with you the PHP implementation of FTP upload files a simple example. Hope that everyone's PHP learning can bring some help.
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 Fals E 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 are not a file or not a directory if (@ftp_c Hdir ($ftp _stream, $dir)) {//If it is a directory and then the directory of the original directory Ftp_ ChDir ($ftp _stream, $original _directory); return true; } else {return false; }} $conn = Ftp_connect ("FTP address") or Die ("Could not Connect"), Ftp_login ($conn, "Ftpname", "password");//Create Directory with FTP Make_ Directory ($conn, $path);//Using FTPSelect Enter Directory Ftp_chdir ($conn, $path);//Start uploading 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);//Note the FTP permission settings on the upload side
Friends who are interested can test run or rewrite the code described in this article, and deepen understanding while allowing the code to function more fully.
http://www.bkjia.com/PHPjc/867242.html www.bkjia.com true http://www.bkjia.com/PHPjc/867242.html techarticle PHP Implementation of FTP upload file example, FTP upload is a common and very important application of PHP implementation skills, today to share with you the PHP implementation of FTP upload file simple example. Hope ...