php初學篇-php檔案上傳教程_PHP教程

來源:互聯網
上載者:User
html表單上傳代碼


下面 是php檔案上傳功能代碼

function uploadfile($type,$name,$ext,$size,$error,$tmp_name,$targetname,$upload_dir)
{
$max_size = 2000000;
$file_mimes = array('image/pjpeg','image/jpeg','image/jpg','image/gif','image/png');
$file_exts = array('.jpg','.gif','.png','.jpg','.gif','.png');
$file_path = $upload_dir.$targetname;
if(!is_dir($upload_dir))
{
if(!mkdir($upload_dir))
die("檔案上傳目錄不存在並且無法建立檔案上傳目錄");
if(!chmod($upload_dir,0755))
die("檔案上傳目錄的許可權無法設定為可讀可寫");
}
if($size>$max_size)
die("上傳的檔案大小超過了規定大小");
if($size == 0)
die("請選擇上傳的檔案");
if(!in_array($type,$file_mimes) || !in_array($ext,$file_exts))
die("請上傳符合要求的檔案類型");
if(!move_uploaded_file($tmp_name, $file_path))
die("複製檔案失敗,請重新上傳");
switch($error)
{
case 0:
return ;
case 1:
die("上傳的檔案超過了 php.ini 中 upload_max_filesize 選項限制的值");
case 2:
die("上傳檔案的大小超過了 html 表單中 max_file_size 選項指定的值");
case 3:
die("檔案只有部分被上傳");
case 4:
die("沒有檔案被上傳");
}
}

http://www.bkjia.com/PHPjc/444797.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444797.htmlTechArticlehtml表單上傳代碼 form enctype=multipart/form-data action=upload.php教程 method=post input type=hidden name=max_file_size value=100000 input name=userfile type=file input ty...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.