php上傳圖片之時間戳記命名(儲存路徑),_PHP教程

來源:互聯網
上載者:User

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...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.