2009-09-04 141 views

回答

4

不知道我理解你,但我會盡力回答。

http://www.w3schools.com/PHP/php_file_upload.asp

你能在這裏學到的是,每個文件上傳到PHP的臨時目錄。然後由腳本將該文件移動/複製到某個永久性的Web可訪問目錄,因爲在腳本執行完畢後,上傳到php臨時目錄的文件將被刪除。

+0

您理解正確 - 我只使用該文件讀取其中的數據,並且如果不需要,我不想將文件存儲在文件系統上。 – jimyi 2009-09-04 20:16:57

+0

那麼我不認爲你必須除了上傳文件和exectute腳本旁邊的其他任何東西。執行後 - 文件被刪除。 :) – Gavrisimo 2009-09-04 20:18:37

0

在Linux上,您可以在內存中創建文件系統分區。如果你可以確保上傳的文件被寫入到內存中的分區,那麼它將被存儲在內存中,但是就像存儲在文件系統中一樣,使Apache/PHP5和你都感到高興。

問題是,任何解決方案將文件寫入內存而不是文件系統需要嚴格限制文件的大小和數量。通過避免寫入磁盤,您將看到速度提升,但如果您使用足夠的內存將其他數據推入頁面文件或交換,您的「優化」將很快產生反作用。

0

您可以:

<?php 
if (!empty($_FILES)) 
{ 
    echo "<pre>"; 
    print_r($_FILES); 
    echo file_get_contents($_FILES['file']['tmp_name']); 
    echo "</pre>"; 
} 
?> 
<form id="myForm" method="post" enctype="multipart/form-data"> 
    <input type="file" name="file" /> 
    <input type="submit" value="Send" /> 
</form> 

輸出:

Array 
(
    [file] => Array 
     (
      [name] => mytextfile.txt 
      [type] => text/plain 
      [tmp_name] => D:\PHP\wamp\tmp\php1283.tmp 
      [error] => 0 
      [size] => 1473 
     ) 

) 
My text file My text file My text file My text file My text file My text file 
My text file My text file My text file My text file 
My text file My text file My text file My text file My text file My text file 
My text file My text file My text file 
My text file My text file My text file My text file My text file 

,如果它是由一些php.ini中變量的限制,我不知道。

+1

從文件系統讀取文件 - 顯然這並不能解決他的問題。 – Craig 2009-09-04 20:34:49

+0

我知道如何讀取文件 - 我的問題是關於讀取文件而不寫入文件系統。隨着你發佈的內容,上傳的文件被寫入D:\ PHP \ wamp \ tmp \ – jimyi 2009-09-04 20:35:09

+0

我的錯誤是這樣的,但你的問題並不十分清楚。 – inakiabt 2009-09-05 01:55:16