You can store image data in session as base encoded one easily. In production server you are supposed to have enough RAM.
My application needed upto 40MB of 4 images/apps for update and change before putting in mongoDB.
(Base encoding makes 1.3 times larger image size.)
$tmpNameSS1 = $_FILES["screenshot1"]["tmp_name"];
$fp = fopen($tmpNameSS1, 'r');
$rawDataSS1 = fread($fp, filesize($tmpNameSS1));
fclose($fp);
$SS1FileName = $_FILES["screenshot1"]["name"];
$encodedSS1Data = base64_encode($rawDataSS1);
registry::update('sCreateSS1Name', $SS1FileName);
registry::update('sCreateSS1Data', $encodedSS1Data);
A case will be: you have multiple image to uploaded and both client and server validation for size and type. It is faster to fetch from session.
After putting in DB null the variable holding the image.
Browser will show show that image with:
<img src="data:image/;base64,<?php echo registry::get('sCreateSS1Data'); ?>"/>
You can update the session for the image with empty string after the code reaches the end of the block. Typical case is updating form field with validation and when the user wants to change the text. You also want to show what image was uploaded between those failed updates. If you want to save the round trip (advisable) keep data for some moments in the session and empty that value after code is about exit.