How do I upload files across servers across a domain across a network? The most basic way to upload is:
1. Users upload files to the Web server
2. Web server uses the Move_uploaded_file () function to move files to the specified folder
However, sometimes we need to put the uploaded files to another dedicated file server, this time, we can not use Move_uploaded_file () to move files, and need to use FTP to transfer files to the file server, the method is very simple ...
See Code directly:
The code is as follows |
Copy Code |
$file = $_files[' file ']; $file _tmp = $file [' Tmp_name ']; $file _name = $file [' name ']; if (Is_uploaded_file ($file _tmp)) {//Make sure the user has an "upload" file $file _ext = STRRCHR ($file _name, '. '); File names of files to upload $file _name_new = Date (' Ymdhis '). $file _ext; $host = ' 127.0.0.1 '; $port = ' 21 '; $user = ' admin '; $pass = ' 123456 '; $link = Ftp_connect ($host, $port); $login = Ftp_login ($link, $user, $pass); Ftp_chdir ($link, ' filedir '); Switch to the folder where you want to put the file if (Ftp_put ($link, $file _name_new, $file _tmp,ftp_binary)) { $msg = ' upload success '; }else{ $msg = ' upload failed '; } }else{ $msg = ' upload failed '; } Ftp_close ($link); Echo $msg; |