<?php Tutorial
//user upload image Processing file
if (($_files["File" ["type"] = = "Image/gif") | | ($_files["File"] ["type"] = = "Image/jpeg") | | ($_files["File"] ["type"] = = "Image/pjpeg") && ($_files["file"] ["size"] < 100000) {//control the type of picture allowed to upload, the last 100000 is the allowed picture size
if ($_files["file"] ["Error"] > 0 {
echo "return Code:".) $_files["File" ["Error"]. "<br/>"; Error returns
}else{
///This is the upload image information, remove the comments before and after you can see the effect.
echo "Upload:". $_files["File" ["Name"]. "<br/>";
echo "Type:". $_files["File" ["type"]. "<br/>";
echo "Size:". ($_files["File"] ["size"]/1024). "Kb<br/>";
echo "Temp file:". $_files["File" ["Tmp_name"]. "<br/>"; */
if (file_exists ("userupload/". $_files["File" ["Name"])) {
echo $_files["file" ["Name"]. "already exists."
}else{
Move_uploaded_file ($_files["File" ["Tmp_name"], "userupload/". $_files["File" ["name"]);
}
$date =date (' ymdhis '); To get the current time, such as; 20070705163148
$fileName =$_files[' file ' [' Name ']; Get the name of the uploaded file
$name =explode ('. ', $fileName); Place file name with '. ' The partition gets the suffix name and gets an array
$newPath = $date. $name [1]; Get a new file for ' 20070705163148.jpg ', that is, the new path
$oldPath =$_files[' file ' [' Tmp_name ']; temporary folder, which is the previous path
Rename ("userupload/". $fileName, "userupload/". $newPath);
Here you can write your SQL statement, the image address is "userupload/". $newPath
?>
<script type= "Text/javascript Tutorial" >alert (' Picture upload success!! '); </script>
<?php
}
}else{
echo "Invalid file"; Wrong picture type or too big
}
?>