<! -- Upload photo example upimage. php
Function: Upload a photo to display 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. Program You can automatically create a file photo.txt and a directory image. If the file cannot run normally, create a file photo.txt (in the same directory as upimage. php) and a directory image.
3. You can test the http://medonline.51.net/upload/upimage.php on my homepage
-->
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> upload a photo </title>
<Style type = "text/CSS">
<! --
. White12 {font-size: 12pt; color: # ffffff; text-Decoration: None}
. Blue10 {font-size: 10pt; color: #99 CCFF; text-Decoration: None}
. Black10 {font-size: 10pt; text-Decoration: None}
-->
</Style>
</Head>
<Body bgcolor = "# ffffff">
<? PHP
If ($ upload) {// if you click "Upload", execute this PHP Code Part
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 a line break to <br>.
$ Text = "photo name: <a href = 'image/$ picurl_name 'target = '_ blank'> $ picurl_name </a> <br> Photo size: $ picurl_size byte <br> photo Description: <br> <SPAN class = 'blue10'> $ photonote </span> <br> <Div align = 'right'> uploaded: $ user ($ mydate) </div> <HR> ";
// Write content
Fwrite ($ FP, $ text, strlen ($ text); // strlin calculates the string length of $ text
Fclose ($ FP );
Echo "File Uploaded successfully! <Br> ";
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.
}
?>
<Table width = "71%" border = "0" cellspacing = "0" cellpadding = "0" align = "center">
<Tr bgcolor = "# 6699ff">
<TD>
<Div align = "center" class = "white12"> All photos </div>
</TD>
</Tr>
<Tr>
<TD class = "black10">
<? PHP
// Display previous uploaded photo information
Readfile ("photo.txt ");
?>
</TD>
</Tr>
<Tr bgcolor = "# 6699ff">
<TD>
<Div align = "center" class = "white12"> upload a photo </div>
</TD>
</Tr>
<Tr>
<TD>
<Form action = "upimage. php" method = "Post" enctype = "multipart/form-Data" name = "Ul">
<! -- Note: 'enctype = "multipart/form-Data" 'must be added here; otherwise
Transmission -->
<Div align = "center" class = "black10"> source image file:
<Input type = "file" name = "picurl" size = "15" Accept = "image/X-PNG, image/GIF, image/JPEG">
<Br>
Photo Description: (up to 50 characters) <br>
<Textarea name = "photonote" Cols = "50" rows = "5"> </textarea>
<Br> uploaded:
<Input type = "text" name = "user" size = "10" maxlength = "10">
<Br>
<Input type = "Submit" name = "Upload" value = "Upload">
<Input type = "reset" name = "reset" value = "Rewrite">
</Div>
</Form>
<Div align = "center" class = "blue10"> <a href = "javascript: history. Back ()"> return </a> </div>
</TD>
</Tr>
</Table>
</Body>
</Html>
[This article is copyrighted by the author and osuo. If you need to reprint it, please indicate the author and its source]