Example code for uploading images in php _ PHP Tutorial

Source: Internet
Author: User
Tags php form
Example code for uploading images in php. Example code for uploading images in php below is the example code for uploading images in PHP. The first page is the table single page upfiles_frm.php. Code Title: upload File: The second page is the example code for processing image uploads in php form

The following is the example code for uploading images in PHP. The first page is the table single page upfiles_frm.php.

Code

Title:

Upload files:

The second page is processing the single page of the table upfiles_add.php

Code 1

2 $ mkdir_file_dir = mkdir ('./img/'. $ _ POST ['title'], 0777); // create an image-related directory when uploading a file

3 $ tmp_file_name = $ _ FILES ['file'] ['tmp _ name']; // temporary file name obtained after successful Upload

4 $ file_name = $ _ FILES ['file'] ['name']; // original file name

5

6 $ file_dir = '. /img /'. $ _ POST ['title']. '/'; // assign a created directory to a variable as the final storage directory

7

8 if (is_dir ($ file_dir ))

9 {

10 move_uploaded_file ($ tmp_file_name, $ file_dir. $ file_name); // start to move the file

11}

12?>

// Create a folder img under the file directory

Create a file and try again in the php environment!

The following is the example code for uploading images in PHP. The first page is the upfiles_frm.php page of the table. Code Title: upload File: The second page is processing form...

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.