A good way to implement file upload in PHP_PHP tutorial

WBOY
Release: 2016-07-20 11:04:33
Original
786 people have browsed it

P & GT; There are many personal homepage spaces that support PHP on the Internet. At this time, you may think of something uploaded, but after all, it is free. Of course, there will be a lot of restrictions. Even the Mail() function is not used. In this case, there is no way to upload. PHP supports powerful sockets. Of course, direct operation of ftp is indispensable. Just look at the function table and you can upload files through ftp. Isn’t it great? Don’t we use ftp to upload the home page?
The implementation code is as follows:
//upload.php



Upload file:


$ftp_server="ftp server (preferably use IP)";
$ftp_username="ftp username";
$ftp_password="Login password";
$ftp_dir="Directory (such as Set to /)";
if ($action == "OK")
{
$con = ftp_connect($ftp_server); //Connect ftp
ftp_login($con, $ftp_username, $ftp_password); //User login
$suss=$con;
ftp_chdir($suss, $ftp_dir); //cd to the specified directory
$ok_code = ftp_put($suss, $upload_file_name, $ upload_file, FTP_BINARY); //put file

if ($ok_code == 1)
{
echo "File uploaded successfully!";
}
else
{
echo "File upload failed!";
}
ftp_quit($suss); // Close ftp connection
}
?>




www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445194.htmlTechArticleP There are many free personal homepage spaces on the Internet that support PHP. At this time, you may think of uploading something. Yes, but it is free after all. Of course there will be many restrictions and uploading is not allowed...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template