The ultimate solution of ftp_connect for php in centos
Uploading images through FTP in the test php today. After the code is written, there is no problem in testing in the win system, but in centos, it is basically invalid.
Check and find that the connection to Step 1 ftp_connect fails.
Almost no complete solution is available in Baidu. You can only find the cause step by step.
Finally, the first problem was found. The FTP component was not installed. Solution: refer to the FTP component installation process record in centos.
After the first problem is solved, apache cannot be connected again. It's annoying!
Check the firewall and permissions. No problem ............
Finally, the second problem was found. After SELinux was closed, the FTP connection was normal ............
Solution: Refer to SELinux introduction and close
The following is a simple FTP function:
$ Ftpserver = "192.168.1.10"; $ conn = ftp_connect ($ ftpserver); // open the connection. The default value is port 21. Therefore, ftp_login ($ conn, 'root ', '000000'); // authenticate ftp_pasv ($ conn, 1); // open the passive mode ftp_put(+conn,'1.txt','1.txt ', FTP_BINARY); // transfer the file ftp_close ($ conn); // close the connection