天天看點

[PHP] 超全局變量$_FILES上傳檔案

1.$_FILES --超全局變量,HTTP 檔案上傳變量

通過 HTTP POST 方式上傳到目前腳本的項目的數組,PHP 能夠接受任何來自符合 RFC-1867 标準的浏覽器上傳的檔案,

上傳的過程中,檔案存放在/tmp/phpXxXxx裡,有的時候磁盤滿了,/tmp/下放不了檔案也會報錯

[PHP] 超全局變量$_FILES上傳檔案

2.RFC 1867标準

RFC 1867 - Form-based File Upload in HTML

<FORM ENCTYPE="multipart/form-data" ACTION="_URL_" METHOD=POST>

File to process: <INPUT NAME="userfile1" TYPE="file">

<INPUT TYPE="submit" VALUE="Send File">

</FORM>

2.move_uploaded_file ( string $filename , string $destination )

将上傳的檔案移動到新位置,企郵預設從/tmp/phpxxxx到/mnt/entmail/webapp/uploads

3.上傳多個檔案

<input name="userfile[]" type="file" /><br />

擷取$_FILES['userfile']['tmp_name'][0],$_FILES['userfile']['tmp_name'][1]

<?php
/* PUT data comes in on the stdin stream */
$putdata = fopen("php://stdin", "r");

/* Open a file for writing */
$fp = fopen("myputfile.ext", "w");

/* Read the data 1 KB at a time
   and write to the file */
while ($data = fread($putdata, 1024))
  fwrite($fp, $data);

/* Close the streams */
fclose($fp);
fclose($putdata);
?>      
php