PHP (Hypertext Preprocessor) is an HTML embedded language (similar to ASP on IIS). And PHP's unique syntax mixes C, Java, Perl, and new PHP-like syntax. It can execute dynamic web pages faster than CGI or Perl. In addition, web back-end CGI programs written in PHP can be easily ported to different system platforms.
When we build a website, we need the participation of visitors to make the website more eye-catching, which requires us to get articles, pictures, etc. from visitors. Therefore, file upload has become an essential function in web pages. Now I will use the popular programming language PHP to illustrate the implementation of its functions in two ways.
1. Use PHP’s file function to upload.
This code is divided into two files, one is upload.html and the other is upload.php.
Upload file selection: upload.html code is as follows:
Upload file form
*** Description***
1. Please note that
Process uploaded files: ftp.php The code is as follows:
//ftp connection host function
function connect()
{
global $server, $username, $password;
$conn = ftp_connect($server);
ftp_login($conn, $username, $password);
return $conn;
}
//Establish ftp connection
$result = connect();
if ($action = = "Upload")
{
//Used to change the ftp path
ftp_chdir($result, $cdir);
//Used to Upload the specified file with the same name and pass it in binary bits
$res_code = ftp_put($result, $upfile_name, $upfile, FTP_BINARY);
// Determine whether the upload is correct
if ($res_code == 1)
echo "Upload successful!";
else
echo "Upload error!";
}
//Close the connection
ftp_quit($result);
?>
*** Description***
Function ftp_put(int ftp_stream, string remote_file, string local_file, int mode) Usage
Return value: Boolean value
This Function is used to upload the specified file. The parameter ftp_stream is the FTP connection code. The parameter remote_file is the name of the file to be stored remotely. The parameter local_file is the file name of the file to be uploaded. There are two values of parameter mode: FTP_ASCII and FTP_BINARY, which represent documents or binary files respectively. Returns a true value on success and a false value on failure.
http://www.bkjia.com/PHPjc/314237.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314237.htmlTechArticlePHP (Hypertext Preprocessor) is an HTML embedded language (similar to ASP on IIS). And PHP's unique syntax mixes C, Java, Perl, and new PHP-like syntax. It can be better than CGI or...