PHP File Upload Simple implementation method, _php tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.