Php photo upload and management example

Source: Internet
Author: User
& Lt ;! -- Upload photo example upimage. php function: upload a photo to show the uploaded person, upload time, image name, image size, and image description. Note: 1. some home page spaces may not support temporary file operations after uploading. you can only try another one. 2. the program can automatically create a file photo.txt and a directory image. if the file cannot run normally, create a file photo.txt (same as upimage. php ).



Upload photo



If ($ upload) {// if you click "upload", run the php code section
If ($ picurl = "none "){
Echo "you have not uploaded any files .";
Exit; // exit the program if no file is uploaded
}
$ V = opendir ("image ");
If ($ v = 0)
{Mkdir ("image"); // if the directory does not exist, create
$ V = opendir ("image"); // Get the directory handle
}
$ Up = copy ("$ picurl", "image/$ picurl_name"); // The key step is to copy the temporary file to the image directory.
If ($ up = 1)
{
// File operations
$ Fp = fopen ("photo.txt", "a"); // open the file and write the message as an addition.
// Initialize the written content
$ Mydate = date ("Y, m, d, h: I ");
$ Photonote = nl2br ($ photonote); // convert the line feed
.
$ Text = "photo name: $ picurl_name
Photo size: $ picurl_size byte
Photo description:
$ Photonote

Uploaded by: $ user ($ mydate)

";
// Write content
Fwrite ($ fp, $ text, strlen ($ text); // strlin calculates the string length of $ text
Fclose ($ fp );
Echo "file uploaded successfully!
";
Unlink ($ picurl); // delete a file from a temporary folder $ picurl
Closedir ($ v); // Close the directory handle
}
Else
{Echo "file Upload failed."; exit;} // exit the program if the upload fails.
}
?>













                               
 
   

All photos


  
 
    // Display previous uploaded photo information
Readfile ("photo.txt ");
?>
  
 
   

Upload photo


  
 
   
   

Return


  


 

[This article is copyrighted by the author and osuo. if you need to reprint it, please indicate the author and its source]

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.