PHP Upload, manage photo sample _php Basics
Last Update:2017-01-19
Source: Internet
Author: User
<!--upload Photos sample upimage.php
function: Upload photos, show the descendants, upload time, picture name, picture size, picture description.
Note: 1. Some of the home page space may not support the temporary file after the upload operation, it can only be another try.
2. The program can automatically create new document Photo.txt and directory image, if not normal operation, please create a new document Photo.txt (and upimage.php under the same directory) and directory image.
3. You can test the http://medonline.51.net/upload/upimage.php on my home page.
-->
<HTML>
<HEAD>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<TITLE> Upload Photos </TITLE>
<style type= "Text/css" >
<!--
. white12 {font-size:12pt; color: #FFFFFF; Text-decoration:none}
. blue10 {font-size:10pt; color: #99CCFF; 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 section
if ($picurl = = "None") {
echo "You didn't upload any files."
Exit If no file is uploaded, exit the program
}
$v =opendir ("image");
if ($v ==0)
{mkdir ("image");//If the directory does not exist, create a new
$v =opendir ("image"); Get directory Handle
}
$up =copy ("$picurl", "image/$picurl _name"); The key step is to copy the temporary files to the image directory
if ($up ==1)
{
File actions
$FP =fopen ("Photo.txt", "a");//Open file, add way to write message
Initializing write content
$mydate =date ("Y-year m-month D-day h:i A");
$photonote =nl2br ($photonote);//convert newline characters 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 ' > Uploading Person: $user ($mydate) </div>Write content
Fwrite ($fp, $text, strlen ($text)); Strlin compute the string length of $text
Fclose ($FP);
echo "File upload successful!<br>";
Unlink ($picurl); Delete files from the temporary folder $picurl
Closedir ($v); Close directory Handle
}
Else
{echo "File upload failed."; exit;} If upload fails, exit program
}
?>
<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
Show previous uploaded photos information
ReadFile ("Photo.txt");
?>
</td>
</tr>
<tr bgcolor= "#6699FF" >
<td>
<div align= "center" class= "white12" > Upload photos </div>
</td>
</tr>
<tr>
<td>
<form action= "upimage.php" method= "post" enctype= "Multipart/form-data" name= "UL" >
<!--Note: Here must be added ' enctype= ' multipart/form-data ', otherwise it will not produce on
Movement-->
<div align= "center" class= "BLACK10" > Image source file:
<input type= "File" Name= "Picurl" size= "accept=" "Image/x-png,image/gif,image/jpeg" >
<br>
Photo Description: (no more than 50 words) <br>
<textarea name= "Photonote" cols= "rows=" 5 "></textarea>
<br> Upload Person:
<input type= "text" name= "user" size= "ten" maxlength= "ten" >
<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 copyright belongs to the author and the Osso net jointly owns, if needs to reprint, please indicate the author and the origin"