PHP - Store Images in SESSION data?

后端 未结 7 993
一向
一向 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:49

    Sometimes We need to preview/confirm page before save data into database. But Image file to the confirm page is a little bit differnt.You cant do $_SESSION['s_name'] = $_FILES['f_name'] coz SESSION just keep the text file. In the alternative way keeping file contents/binary value in session.

    $_SESSION['obj_image_session'] = file_get_contents($_FILES['image_name']['tmp_name']);
    
    $file= "new_file.jpg";
    $fp=($file,"w");
    
    fwrite($fp,$_SESSION['obj_image_session']);
    

提交回复
热议问题