php檔案上傳

來源:互聯網
上載者:User

標籤:style   http   color   使用   os   檔案   資料   art   

一php.ini 配置有關的事項:

  1.file_uploads=on;  //必須開啟檔案上傳
  2.upload_max_filesize=  最大上傳尺寸

  3.upload_tmp_dir=   檔案上傳的臨時檔案夾

  4.post_max_size 必須大於upload_max_filesize 的尺寸
  

二:表單提交的注意事項:
  1.表單提交必須為HTTP post

  2.表單上傳需要為file的表單

  3.enctype="multipart/form-data" 只有檔案上傳才使用

  4.隱藏表單:MAX_FILE_SIZE= ;提前限制上傳大小避免在PHP程式中上傳之後判斷檔案大小;

   <input type="hidden" name="MAX_FILE_SIZE" value="‘.$maxSize.‘" />

三:接受資料:

  1.使用$_FILES[]超全域數組;接受獲得的資料

  2.使用copy() 拷貝檔案到指定的檔案夾

 

 

step1:使用$_FILES[‘pic‘][‘ERROR‘];檢查錯誤

   0:表示沒有錯誤;

   1:上傳超出了php.ini中的upload_max_filesize;

   2:上傳超出了表單中的MAX_FILE_SIZE;

   3:沒有檔案被上傳

   4:其它錯誤就好了

step2:限制檔案上傳大小$_FILES[‘pic‘][‘size‘];

step3:顯示檔案類型:

    1.使用$_FILES[‘pic‘][‘type‘]===>  image/gif  image/png  image/ipp

        2.使用$_FILES[‘pic‘][‘name‘] ====>

   $arr=explode(‘.‘,$_FILES[‘pic‘][‘name‘]);

   $arr[count($arr)-1];

 

step4: 將檔案上傳後的檔案拷貝:

    is_uploads_file()判斷是不是通過http 上傳的檔案

    if($_FILES[‘pic‘][‘tmp_name‘]){

      move_uploaded_file(file,newloc);

    }

聯繫我們

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