PHP - Store Images in SESSION data?

后端 未结 7 954
一向
一向 2020-12-30 01:21

Can you store an image in a PHP SESSION ?

I have a multi-step registration process using PHP on my site. On one of the steps, the users can upload their company log

7条回答
  •  醉梦人生
    2020-12-30 01:47

    You can but expect memory usage of your session to increase depending on the size of the images. In order to do so, you must save the file contents into a session variable.

    If it is in session data and you have multiple steps after the upload the image will be reloaded (into the session) every page view until the steps are complete.

    I would personally recommend against using the session for holding a binary file. Saving the image on disk into a temporary location until the registration is complete. I would only save the path to the temporary file in session. When the transaciton is completed move it to a proper location and do your db inserts.

    Also, in essence, session data is stored on disk (or db) anyway so you might as well save the image file once then issue a move command once complete.

提交回复
热议问题