<?php
if($_FILES['file']['error'] > 0){
echo '!problem:';
switch($_FILES['file']['error'])
{
case 1: echo '檔案大小超過伺服器限制';
break;
case 2: echo '檔案太大!';
break;
case 3: echo '檔案只載入了一部分!';
break;
case 4: echo '檔案載入失敗!';
break;
}
exit;
}
if($_FILES['file']['size'] > 1000000){
echo '檔案過大!';
exit;
}
if($_FILES['file']['type']!='image/jpeg' && $_FILES['file']['type']!='image/gif'){
echo '檔案不是JPG或者GIF圖片!';
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 '移動檔案失敗!';
exit;
}
}
else
{
echo 'problem!';
exit;
}
echo '<h1>success!</h1><br>';
echo '檔案大小:' . $_FILES['file']['size'] . '位元組' . '<Br>';
echo '檔案路徑:' . $upfile;
echo '<hr with="100%" />' . '<p>';
$dirr = 'upfile/';
$dir = opendir($dirr);
echo $dirr . '--Listing:<ul>';
while($file = readdir($dir)){
echo "<li>$file</li>";
}
echo '</ul>';
closedir($dir);
?>