Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP File upload to memory

I would like to upload a file from an html form, post it to PHP and load it into memory, bypassing writing it to a file. Is it possible to do a file upload and keep it in memory, or do I have to write it to a file?

like image 836
CLJ Avatar asked Oct 16 '09 19:10

CLJ


People also ask

How can I upload large files over 500mb in PHP?

By changing the upload_max_filesize limit in the php. ini file. By implementing file chunk upload, that splits the upload into smaller pieces an assembling these pieces when the upload is completed.

How can get upload file size in PHP?

The filesize() function in PHP is an inbuilt function which is used to return the size of a specified file. The filesize() function accepts the filename as a parameter and returns the size of a file in bytes on success and False on failure.

How can we store uploaded file in database using PHP?

Get the file extension using pathinfo() function in PHP and validate the file format to check whether the user selects an image file. Upload image to server using move_uploaded_file() function in PHP. Insert image file name in the MySQL database using PHP. Upload status will be shown to the user.


2 Answers

The PUT option is cool. If you wanted to use POST and $_FILES, I think the closest you could get would be to point upload_tmp_dir at a ramdisk.

like image 128
Mat Schaffer Avatar answered Nov 01 '22 07:11

Mat Schaffer


I do not think this is possible now. You can not use php://input with enctype="multipart/form-data", so that rules out opening the file from a stream. If you go the post route, you only can use the $_FILE variable, which does not contain any binary data, just the pointer to the file on disk.

It looks like xforms will help (http://www.ibm.com/developerworks/xml/library/x-xformstipuploadphp/index.html) but this is in even Firefox 3.5. It requires a plug-in, which is a deal killer for me.

like image 34
CLJ Avatar answered Nov 01 '22 07:11

CLJ