<?php
$upload_path = "upload/";
//以下$max_size=???只需留一行,其他前面加//或刪除整行------------------------
//$max_size = 1; //限制可檔案大小為1位元組
//$max_size = 2*1024; //限制可檔案大小為2KB
$max_size = 3*1024*1024; //限制可檔案大小為3MB
//$max_size = 4*1024*1024*1024; //限制可檔案大小為4GB
//解說:1GB=1024MB,1MB=1024KB,1KB=1024位元組-------------------------------
$limitedext = array("bmp","gif","jpg","jpeg","png","tif","cur","ani","css","stm","xml");//設定可上傳的檔案類型(副檔名)
$File_Extension = explode(".", $_FILES[\'uploadedfile\'][\'name\']);
$File_Extension = $File_Extension[count($File_Extension)-1];
$photoinfo=getimagesize($_FILES[\'uploadedfile\']);
$photowidth=$photoinfo[0]; //$photowidth是此圖寬
$photoheight=$photoinfo[1]; //$photoheight是此圖高
$max_photowidth=500; //設定圖片最大寬度(像素)
$max_photoheight=800; //設定圖片最大高度(像素)
if(!isset($_FILES[\'uploadedfile\']) && sizeof($_FILES[\'uploadedfile\']) < 0){
echo "尚未選擇檔案";
exit;
}
elseif($_FILES[\'uploadedfile\'][\'error\'] > 0){
echo "上傳錯誤代碼:".$_FILES[\'uploadedfile\'][\'error\'];
exit;
}
elseif(($max_size > 0) && ($_FILES[\'uploadedfile\'][\'size\'] > $max_size)){
echo "您上傳的檔案大小大於".$max_size."位元組";
exit;
}
elseif(!in_array($File_Extension,$limitedext)){
echo "不支援此檔案類型";
exit;
}
elseif($photowidth>$max_photowidth){
echo "此圖太寬";
}
elseif($photoheight>$max_photoheight){
echo "此圖太高";
}
elseif(!is_dir($upload_path) && !mkdir($upload_path)){
echo "系統無法新增資料夾";
exit;
}
elseif(!file_exists($upload_path . basename($_FILES[\'uploadedfile\'][\'name\']))){
if(move_uploaded_file($_FILES[\'uploadedfile\'][\'tmp_name\'], $upload_path . basename($_FILES[\'uploadedfile\'][\'name\']))){
echo "上傳成功\!<br>";
echo \'點<a href="\' . $upload_path . basename($_FILES[\'uploadedfile\'][\'name\']) . \'">這裡</a>下載您的檔案\';
exit;
}
else{
echo "檔案上傳失敗";
}
}
elseif(file_exists($upload_path . basename($_FILES[\'uploadedfile\'][\'name\']))){
$time=time();
if(move_uploaded_file($_FILES[\'uploadedfile\'][\'tmp_name\'], $upload_path.$time.basename($_FILES[\'uploadedfile\'][\'name\']))){
echo "上傳成功\!<br>";
echo \'點<a href="\' . $upload_path.$time.basename($_FILES[\'uploadedfile\'][\'name\']) . \'">這裡</a>下載您的檔案\';
exit;
}
else{
echo "檔案上傳失敗";
}
}
?>
|