PHP Image Upload Server

Source: Internet
Author: User

The principle is to upload the image to a directory on the server, and then save his name in the database, or do not need the database part of the line. Read the name directly when reading.





HTML Submission Form

<formMethod= "POST"Action= "upload_image_todb.php?name=<?php echo $username;? > "enctype= "Multipart/form-data"> <Table> <h4>Select picture<spanclass= "Error Title-error"></span></h4> <Divclass= "Row"><inputtype= "File"name= "image"size= " the" ></Div> <Divclass= "Row"> <inputtype= "Submit"name= "Submit"value= "Upload"/> </Div> </Table> </form>

PHP Operation code

<meta charset= "UTF-8" &GT;&LT;?PHP$user=$_get[' Name '];require(' db_connect.php ');$db=Db_connect ();if(isset($_post[' Submit '])){    $file _name=$_files[' Image '] [' Name '];//file name$file _type=$_files[' Image '] [' Type '];//File Types$file _site=$_files[' Image '] [' Size '];//File Size$file _tmp_name=$_files[' Image '] [' Tmp_name '];//upload file pathif($file _name){}    Move_uploaded_file($file _tmp_name, "images/img/$file _name")//Move the picture to the server directory}$query= "INSERT into image (Name,type,date,user) VALUES ('".$file _name."‘,‘".$file _type. "', Now (), '".$user."‘)";//inserting information into the database$result=$db->query ($query);if($result){    Echo"<script type= ' text/javascript ' >alert (\ "upload success \"); Location.href=\ "Mine.php?uid=".$user." \ ";</script>";}Else{    Echo"<script type= ' text/javascript ' >alert (' upload failed ');</script>";}$folder= "images/img/";//Pathif(Is_dir($folder)){    if($handle=Opendir($folder)){//Open Directory         while(($file=Readdir($handle)) !=false){//The readdir () function returns an entry in a directory handle opened by Opendir (). If successful, the function returns a file name, otherwise it returns false.             if($file= = = '. ' | |$file= = = ' ... ')                Continue; //echo " ' "alt= ' >";        }        Closedir($handle); }}?>

PHP Image Upload Server

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.