Loading a Parse file directly without writing to the file system

With Apache / PHP5, is it possible to directly load the contents of an uploaded file without writing it to the file system?

There isn't much on google, but it seems like the files are always written to the temp directory after they are downloaded.

+2


source to share


3 answers


I'm not sure if I understand you, but I'll try to answer.

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



What you can find out here is that each file is loaded into the php temp directory. Then your script will move / copy that file to some persistent web accessible directory because the file loaded in php temp dir is removed after the script is executed.

+4


source


In Linux, you can create partitions of the filesystem in memory. If you can guarantee that the uploaded file will be written to a section in memory if it is saved in memory, but will act as if it was saved in the filesystem, making both Apache / PHP5 and you happy.



The problem is that any solution that writes files to memory rather than to the filesystem requires severe restrictions on the size and number of files. You will see speed gains by avoiding writing to disk, but if you are using enough memory to enter other data into the paging or swap file, your "optimization" will be very counterproductive.

0


source


You can:

<?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>

      

Output:

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 

      

I don't know if it is limited by some php.ini variable.

0


source







All Articles