PHP File Upload Simple implementation method,
This paper introduces the simple implementation method of PHP file upload. Share to everyone for your reference. Specific as follows:
File 1:index.php
Copy the Code code as follows:
File 2:uploadprocess.php
Copy CodeThe code is as follows: <?php
$filetype _arr = Array ("Image/jpeg", "Image/png", "Image/gif", "image/gif");//The type of picture allowed to upload
if (!empty ($_post[' Sub ')) {
$username = $_post[' username '];//user name
$password = $_post[' pwd '];//password
if (Is_uploaded_file ($_files[' upimage ' [' tmp_name '])) {//Determine if the image is uploaded via http
$tmp _name = $_files[' upimage ' [' tmp_name '];//upload image temporary name
Determine if the image type supports
if (!in_array ($_files[' upimage ' [' type '], $filetype _arr)) {
echo "Sorry, upload image only supported";
foreach ($filetype _arr as $value) {
echo $value. ",";
}
echo "and other types";
Exit ();
}
$exten _name = substr ($_files[' upimage ' [' Name '],strrpos ($_files[' upimage ' [' Name '], ".")); /get the suffix name of the uploaded image
$dest _name = $_server[' Document_root ']. " /php/upfile/". $username." /";//
Determines whether the saved directory exists, does not exist, and creates
if (!file_exists ($dest _name)) {
if (!mkdir ($dest _name)) {//If creation is unsuccessful
echo "Failed to create directory, file cannot be uploaded";
Exit ();
}
}
If a saved directory already exists
if (Move_uploaded_file ($tmp _name, $dest _name.time (). Rand (1,100). $exten _name)) {//move temporary files to the saved directory and rename
echo "Upload image success";
}else{
echo "image upload failed";
}
}else{
echo "Cannot find the image you uploaded, please re-upload";
}
}
?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/947215.html www.bkjia.com true http://www.bkjia.com/PHPjc/947215.html techarticle php File Upload Simple implementation method, the example of this paper describes the PHP file upload simple implementation method. Share to everyone for your reference. The following: File 1:index.php copy code generation ...