Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP $_SESSION can it hold large files?

I'm building a multi-page form with PHP. I'm storing most of the value's in $_SESSION. Using the following method...

$_SESSION['title'] = $_POST['title'];

It's working fine so far but I'm not sure if it will be able to hold PDFs, videos, ect.

Does the $_SESSION only hold strings & intigers, or can files be stored there?

like image 239
Philip Kirkbride Avatar asked Oct 05 '11 20:10

Philip Kirkbride


2 Answers

The maximum size of a $_SESSION is the maximum memory allowed to a PHP script, but chances are if you even get to 1/3 of that, you're doing something wrong.

$_SESSION, as a rule, should only be used to keep what information is needed by the user for the majority of the site page views. It is highly improbable, that you will actually need a file on each page.

Here's a better option, store a temp file on the disk and assign the path to the temp file in the $_SESSION. Then, when you need it, read the file to the user.

like image 149
cwallenpoole Avatar answered Sep 30 '22 15:09

cwallenpoole


I do not suggest you to store big value because this information is stored in your server. You should serialize a PHP object that will contain path to those file if you want to keep some reference to these files.

Edit: The session is loaded into memory at run time, so in theory it's limited by the memory_limit in php.ini.

like image 21
Patrick Desjardins Avatar answered Sep 30 '22 17:09

Patrick Desjardins