php delete image from server after upload & display

html, image, php

Solution

Try another thing: output the image base-64 encoded.

$contents = file_get_contents($file);
$base64 = base64_encode($contents);
echo '<div id="image"><img src="data:image/jpg;base64,'.$base64.'" width="280" height="280"></div>';

(instead of `move_uploaded_file()` etc, use as $file variable the `$_FILES[...]['tmp_name']`)

Problem

Sending an image in my php form, it gets saved onto my server and at the action.php page it gets displayed. Now when I try to: ``` echo '<div id="image"><img src="'.$target_path.'" width="280" height="280"></div>'; ``` it works just fine... but if I add `unlink($target_path);` at the end of my php code it will not even display the image even though it gets deleted AFTER displaying the image... So the question is, how can I display the image and deleting it at the same time so my server does not gets stuffed with user pictures?

Original source