FTP upload is a common and very important implementation of PHP application techniques, today to share with you the PHP implementation of FTP upload file simple example. We hope that the study of PHP can bring some help.
The main code is as follows:
function Make_directory ($ftp _stream, $dir) {//If directory already exists or can is 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 FAL
Se
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 isn't a file or not a directory if (@ftp
_chdir ($ftp _stream, $dir)) {//If It's 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 ("could not Connect");
Ftp_login ($conn, "Ftpname", "password"); Create a directory Make_dir with FTPEctory ($conn, $path);
Use FTP to select access to directory Ftp_chdir ($conn, $path);
Start uploading if (Ftp_put ($conn, $info [0][' Savename '],getcwd (). $upload->savepath. $info [0][' savename]) {
Unlink (GETCWD (). $upload->savepath. $info [0][' Savename ']);
} ftp_close ($conn);
Note The FTP permission settings on the upload side
Interested friends can test run or rewrite the code described in this article, and deepen your understanding while making the code more functional.