Upload images of website production

Source: Internet
Author: User

First, prepare

1. Upload Control <input type= "file" Name= "img"/>

<tr>
<TD align= "Right" > Avatar </td>
<td>
<input type= "File" Name= "Site_logo" size= ""/>
<a href= ". /theme/default/images/logo.gif "target=" _blank "></a>

</td>
</tr>

2. Form form Add attribute enctype= "Multipart/form-data"

    

3, processing the page to get uploaded files information

$_files

Second, the operation process

1, first through the error value to determine if there is a choice to upload pictures

if ($_files[' img ' [' error '] = = 0) When no picture is selected, the value of $_files[' img ' [' ERROR '] is equal to zero

2, perform the upload function move_uploaded_file (temporary storage path, set the project storage path)

$name = Time (). rand (111,999);
$path = ' uplpads/'. $name. JPG ';
Move_uploaded_file ($_files[' img '] [' tmp_name '], $path);

Time () timestamp from the wee hours of January 1, 1970 to the number of seconds elapsed from the execution time

Rand (start number, end number) takes the starting number to the random number of the ending number

3, define the variable $path= "";

If the statement in if is not executed when no picture is selected, then there is no $path variable and an error occurs during execution

4. Assign the path of the uploaded image to the $ variable

Create the Uploads folder in admin

    

5. Add the fields stored in the picture path in the database statement

6, the foreground index.html file to find the location of the graphic, using ' $alt =" image "/> Display image

Upload images of website production

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.