PHP upload picture and show ____php

Source: Internet
Author: User
Tags current time set time
<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "Html/text;charset=utf-8"/>
<body>
<form action= "#" name= "form" method= "POST" enctype= "Multipart/form-data" >
<p>
<input type= "file" Name= "img" value= "choose to upload Files"/>
</p>
<input type= "Submit" value= "Upload"/>
</form>
</body>
<?php
Date_default_timezone_set ("PRC"); Set time zone
if (count ($_files) >0) {
$sort = Array ("Image/jpeg", "image/jpg", "Image/gif", "IMAGE/PDG");
Determine if it is a picture type
if (In_array ($_files[' img '] [' type '], $sort)) {
$IMG = "img"; Gets the location of the uploaded folder
Determine if a folder exists, if there is no creation of a
if (!file_exists ($img)) {
mkdir ("$img", 0700); 0700 Maximum Privileges
}
$time =date ("y_m_d_h_i_s"); Get current time
$file _name = Explode (".", $_files[' img '] [' name ']); $_files[' img ' [' name '] The name of the upload file explode string to interrupt the spin string
$file _name[0]= $time;
$name = Implode (".", $file _name); Implode the array into strings
$img _name = "img/". $name;
if (Move_uploaded_file ($_files[' img '] [' tmp_name '], $img _name)) {//move_uploaded_file Move file
echo "<center>
<p>
<a href= ' img_uploading.php ' > re-upload </a></p></center>;
}else{
echo "Upload failed";
}
}else{
echo "is not a picture type";
}
}
?>


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.