PHP implementation of the image upload instance code

Source: Internet
Author: User
Tags mkdir

The following is the implementation of the image upload in PHP instance code, the first page is the form page upfiles_frm.php.

Code

Title:

Upload file:

The second page is to process the form page upfiles_add.php

Code 1

2 $mkdir _file_dir = mkdir ('./img/'. $_post[' title '],0777); When you upload a file, you start creating a picture-related directory.

3 $tmp _file_name = $_files[' file ' [' Tmp_name ']; Temporary file name after successful upload

4 $file _name = $_files[' file ' [' Name ']; The original file name

5

6 $file _dir = './img/'. $_post[' title '. /'; Assign a value to a directory you create a variable as the final save directory

7

8 if (Is_dir ($file _dir))

9 {

Move_uploaded_file ($tmp _file_name, $file _dir. $file _name); Start moving files

11}

?>

Create a folder in the file directory img

Then create the file, in the PHP environment, try again!

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.