I want the user to be able to upload an image using <input type=\"file\"> and on the following page be able to view the uploaded image.
However, I want the image to viewed from the php temp dir, without being store anywhere else.
I know the file is stored on $_FILES['file']['tmp_name'] but is it possible to show the image from that location or is it deleted immediately?
Do I have to move_uploaded_file from the php temp dir before I can show it on a page, and if so, how do I delete the file automatically after it has been shown?
Appearantly it's not possible to put unlink("dir/file"); right after <img src="dir/file">...

Thanks!

    henkealf wrote:

    Do I have to move_uploaded_file from the php temp dir before I can show it on a page

    For your answer, I quote the manual page [man]features.file-upload[/man]:

    The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.

    What you could do instead is move the uploaded file to your own temporary directory, then have a separate PHP script that outputs image data and then unlink()'s that image.

    That way, you'd move the file, and output:

    <img src="image.php?file=imageName.jpg">

    Then, in your image.php script, you'd do something like:

    if(empty($_GET['file']))
        die('No image specified.');
    else
        $path = basename($_GET['file']);
    
    // output appropriate headers, readfile() the image ($path), then unlink() it
      Write a Reply...