Home > Backend Development > PHP Tutorial > Example code for image uploading in php_PHP tutorial

Example code for image uploading in php_PHP tutorial

WBOY
Release: 2016-07-13 10:22:41
Original
960 people have browsed it

Example code for image upload in PHP

The following is an example code for image upload in PHP. The first page is the form page upfiles_frm.php.

Code

Title:

Upload files:

The second page is the processing form page upfiles_add.php

Code 1

2 $mkdir_file_dir = mkdir('./img/'.$_POST['title'],0777); //Start creating a picture-related directory when uploading files

 3 $tmp_file_name = $_FILES['file']['tmp_name']; //The temporary file name after successful upload

 4 $file_name = $_FILES['file']['name']; //Original file name

 5

 6 $file_dir = './img/'.$_POST['title'].'/'; //Assign the created directory to a variable as the final saving directory

7

 8 if(is_dir($file_dir))

 9 {

10 move_uploaded_file($tmp_file_name,$file_dir.$file_name); //Start moving files

 11}

 12 ?>

//Create a folder img in the file directory

Create the file again, try it again in the php environment!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/847203.htmlTechArticleExample code for image uploading in PHP. The following is an example code for image uploading in PHP. The first page is a form. Page upfiles_frm.php. Code Title: Upload files: The second page is the processing form...
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