PHP檔案上傳實現的注意點

來源:互聯網
上載者:User

上傳介面


假設該介面中的檔案域name為userfile,我們可以通過瀏覽開啟一個檔案選擇視窗,完成選擇後,文字框中會顯示被現實檔案在本地機器上的完整路徑。當按下上傳後,檔案會被傳送到伺服器的臨時目錄上,並且被重新命名為php?.tmp,其中的問號是一個隨機編號。

html代碼如下:

<form action="upload.php" method="post" enctype="multipart/form-data" name="form1" >

<input type="hidden" name="MAX_FILE_SIZE" value="30000"> 

<input name="userfile" type="file" >

<input type="submit" name="Submit" value="上傳"> 

</form>

在傳送到另一個檔案upload.php後,可以通過以下一些變數訪問與該檔案相關的資訊

$userfile_name       上傳文檔名稱

$userfile_tmp_name    上傳文檔儲存到的臨時名稱

$userfile_size        上傳文檔大小,單位bytes

$userfile_type        上傳文檔的mime類型

以上這些變數在windows+apache環境下一切正常,但是如果在linux下出現無法訪問的情況,可以使用以下變數

$_FILE['userfile']['name']        等同於$userfile_name

$_FILE['userfile']['tmp_name']    等同於$userfile_tmp_name

$_FILE['userfile']['size']        等同於$userfile_size

$_FILE['userfile'][type]        等同於$userfile_type

聯繫我們

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