Php photo upload and management example
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]