Upload Picture:
Copy Code code as follows:
if (!empty ($_files["img" ["name"])) {//Extract the File field content name and determine
$path = "uppic/"; Upload path
if (!file_exists ($path))
{
Check if there is a folder, if it is not created, and gives the highest permissions
mkdir ("$path", 0700);
}//end IF
File formats that allow uploading
$TP = Array ("Image/gif", "Image/pjpeg", "image/jpeg");
Check whether the uploaded file is in the type allowed to upload
if (!in_array ($_files["img"] ["type"], $TP))
{
echo "<script>alert" (' Wrong format '); History.go ( -1);</script> ";
Exit
}//end IF
$filetype = $_files[' img '] [' type '];
if ($filetype = = ' Image/jpeg ') {
$type = '. jpg ';
}
if ($filetype = = ' Image/jpg ') {
$type = '. jpg ';
}
if ($filetype = = ' Image/pjpeg ') {
$type = '. jpg ';
}
if ($filetype = = ' Image/gif ') {
$type = '. gif ';
}
if ($_files["img"] ["name"])
{
$today =date ("Ymdhis"); Get time and assign value to variable
$file 2 = $path. $today. $type; Full path to Picture
$img = $today. $type; Picture name
$flag = 1;
}//end IF
if ($flag) $result =move_uploaded_file ($_files["img"] ["Tmp_name"], $file 2);
Special note Here The first parameter passed to Move_uploaded_file is the temporary file uploaded to the server
}//end IF
This will then write the $img value to the corresponding field in the database.
To delete a picture:
Copy Code code as follows:
Unlink ("uppic/". $img); Of course, the value of the variable is read from the database, php delete pictures more concise than the ASP