標籤:style class blog code http ext
<?php$fileup = 0; //上傳功能開關 0開啟 1關閉$filesize = 200; //檔案大小單位KB 1M=1024KB$filepath = ‘./pic/‘; //檔案儲存目錄 後面要加斜杠/header(‘Content-Type: text/html; charset=UTF-8‘);//頁面編碼if(isset($_GET[‘up‘])){ if($fileup) exit (‘上傳功能已關閉!‘); $fileend = end(explode(‘.‘,basename($_FILES[‘file‘][‘name‘])));//取得尾碼名 //判斷檔案類型和大小 if( ( ($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/bmp") ) && $_FILES[‘file‘][‘size‘] < 1024*$filesize ){ if(!file_exists($filepath)) mkdir ($filepath);//判斷檔案儲存目錄是否存在 沒有則建立 date_default_timezone_set(‘PRC‘);//中國時間 $fileurl = $filepath.date(‘YmdHis.‘).$fileend;//檔案路徑 使用年月日時分秒作為檔案名稱 move_uploaded_file($_FILES[‘file‘][‘tmp_name‘],$fileurl);//移動檔案到指定路徑 }else{ exit(‘<script>alert("檔案大小或類型錯誤!");location="?";</script>‘); }}?>
檔案只是驗證了$_FILES["file"]["type"]。沒有其他地方進行驗證。
可以修改POST資訊中的$_FILES["file"]["type"]檔案類型為圖片的類型就可繞過。
提交POST後,關閉代理,就能發現成功上傳了PHP了。