Home > Backend Development > PHP Tutorial > PHP5 image upload code, date folder, random file name_PHP tutorial

PHP5 image upload code, date folder, random file name_PHP tutorial

WBOY
Release: 2016-07-13 17:37:46
Original
1111 people have browsed it

index.htm



 



upload.php

$f=$_FILES[jeff_img_upload];

//Judge whether the file has been uploaded
if ($f[error]==4){
echo("<script>alert(Please select the file you want to upload, thank you!);location.href=index.htm;</script>");
}
else{
//Error judgment
if ($f[error]){
echo "Failed, the file is too large! The error code is".$f[error];
exit;
}

//Type judgment
if (substr($f[type], 0, 5) == image) {
switch ($f[type]) {
case image/jpeg:
case image/jpg:
case image/pjpeg:
$ext = .jpg;
break;
case image/gif:
$ext = .gif;
break;
case image/png:
case image/x-png:
$ext = .png;
break;
                                                                                                                                                                                                               default:
header(Content-type: text/html; charset=UTF-8);
                                                                                                                                            with with echo("
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template