Simple implementation method of php file upload, _PHP tutorial

WBOY
Release: 2016-07-13 10:09:10
Original
941 people have browsed it

A simple way to upload PHP files,

The example in this article describes the simple implementation method of php file upload. Share it with everyone for your reference. The details are as follows:

File 1: index.php

Copy code The code is as follows:

Username:

Password:

Upload image:


File 2: uploadProcess.php

Copy code The code is as follows:
$filetype_arr = array("image/jpeg","image/png","image/gif","image/gif");//The types of images allowed to be uploaded
if(!empty($_POST['sub'])){
$username = $_POST['username'];//Username
$password = $_POST['pwd'];//Password

if(is_uploaded_file($_FILES['upimage']['tmp_name'])){//Determine whether the image is uploaded through http
$tmp_name = $_FILES['upimage']['tmp_name'];//Temporary name of uploaded image
//Determine whether the image type supports
if(!in_array($_FILES['upimage']['type'],$filetype_arr)){
echo "Sorry, uploading pictures is only supported";
foreach($filetype_arr as $value){
echo $value.",";
}
echo "Etc. type";
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."/";//
//Determine whether the saved directory exists, if not, create it
if(!file_exists($dest_name)){
If(!mkdir($dest_name)){//If the creation is unsuccessful
echo "Creation of directory failed, file cannot be uploaded";
exit();
}
}
//If the saved directory already exists
if(move_uploaded_file($tmp_name,$dest_name.time().rand(1,100).$exten_name)){//Move the temporary file to the saved directory and rename it
echo "Picture uploaded successfully";
}else{
echo "Picture upload failed";
}
}else{
echo "The picture you uploaded cannot be found, please upload it again";
}
}
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/947215.htmlTechArticleA simple implementation method for php file upload. This article describes a simple implementation method for php file upload. Share it with everyone for your reference. The details are as follows: File 1: index.php Copy code code...
Related labels:
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