php上傳圖片之時間戳記命名(儲存路徑),
html代碼:
圖片匯入
php代碼:
<?php/***Mwbe Version1.0*-----------------------------------------------*Copy 2013-2014 ylt*Web: communicate*-----------------------------------------------*Author: tao *Data: 2014-7-22*/header("Content-Type:text/html;charset=utf-8");//step 1 使用$_FILES['pic']["error"] 檢查錯誤if(isset($_GET["action"])=="img"){if($_FILES["img"]["error"] > 0){ switch($_FILES["img"]["error"]) { case 1: echo ""; break; case 2: echo ""; break; case 3: echo ""; break; case 4: echo ""; break; default: echo ""; } exit;}$maxsize=2000000; //50k//step 2 使用$_FILES["pic"]["size"] 限制大小 單位位元組 2M=2000000if($_FILES["img"]["size"] > $maxsize ) { echo ""; exit;}//step 3 使用$_FILES["pic"]["type"]或是檔案的副檔名 限制類型 MIME image/gif image/png gif png jpg /* list($dl, $xl) = explode("/", $_FILES["pic"]["type"]); if($dl!="image"){ echo "請上傳一個圖片,不充許其它類型檔案"; exit; } */ $allowtype=array("png", "gif", "jpg", "jpeg"); $arr=explode(".", $_FILES["img"]["name"]); $hz=$arr[count($arr)-1]; if(!in_array($hz, $allowtype)){ echo "";exit; } //step 4 將讓傳後的檔案名稱改名 $filepath="../imgweb/"; $fileimgweb="imgweb/";//為了符合UBB的路徑$randname=date("Y").date("m").date("d").date("H").date("i").date("s").rand(100, 999).".".$hz; //將臨時位置的檔案移動到指定的目錄上即可 if(is_uploaded_file($_FILES["img"]["tmp_name"])){ if(move_uploaded_file($_FILES["img"]["tmp_name"],$filepath.$randname)){ echo ""; session_start(); $_SESSION['images'] = $fileimgweb.$randname; }else{ echo ""; }}else{echo"";}}?>
http://www.bkjia.com/PHPjc/864476.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/864476.htmlTechArticlephp上傳圖片之時間戳記命名(儲存路徑), html代碼: div id="images" style="width:250px;height:120px;background:#fff;border:1px solid #ccc;" h2strong圖片匯入/strong...