if($_FILES['file']['error'] > 0){
echo '!problem:';
switch($_FILES['file']['error'])
{
case 1: echo 'The file size exceeds the server limit';
break;
case 2: echo 'The file is too large! ';
break;
case 3: echo 'Only part of the file is loaded! ';
break;
case 4: echo 'File loading failed! '; The file is too large! ';
exit;
}
if($_FILES['file']['type']!='image/jpeg' && $_FILES['file']['type']!= 'image/gif'){
echo 'The file is not a JPG or GIF image! ';
exit;
}
$today = date("YmdHis");
$filetype = $_FILES['file']['type'];
if($filetype == 'image/jpeg'){
$type = '.jpg';
}
if($filetype == 'image/gif'){
$type = '.gif' ;
}
$upfile = 'upfile/' . $today . $type;
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
if(!move_uploaded_file($_FILES['file']['tmp_name'], $upfile))
{
echo 'Failed to move file! ';
exit;
}
}
else
{
echo 'problem!';
exit; success!
';
echo 'File size:' . $_FILES['file']['size'] . 'Bytes' . '
';
echo 'File path:' . $upfile;
echo '
' . '
';
$dirr = 'upfile/';
$dir = opendir($dirr);
echo $dirr . '--Listing:
';
while($file = readdir($dir)){
echo "< li>$file";
}
echo '
';
closedir($dir);
?>
Second type:
Copy code
The code is as follows: