Display an image that is only saved in the $_FILES array?

I have a form that includes an image upload, which upon submission, needs to generate a preview.

I can think of 2 options…

  1. Save the image to a directory the normal way, and then call it back to generate the preview

Pros: I think I can do it.
Cons: I would have to save the image to my directory before I know if the person actually went through and created the post. They might just preview it, and then close their browser, and then I’d be stuck with a useless image just taking up space. This will create maintenance issues later on.

  1. Open the image right away, before saving it to my directory

Pros: I wouldn’t save something I didn’t need
Cons: I don’t know how to open a file in the $_FILES array.

I tried:
[php][/php]
I think that the “…” means go up one level, and then I tried to find the location of where the temporary files are stored, thinking the $_FILES would go there. This doesn’t work.

Does anyone know if it’s possible to DISPLAY an image that is only saved in $_FILES array?

Are you talking about the $_FILES array created when uploading files? If so I don’t think this will work. I believe the $_FILES array is only information on file name, size etc. You would either need to use javascript or method one as you said, save the file to a directory and display it from there. The issue with this option is that the user has to wait until the whole file is uploaded before they are able to preview it. Which, depending on the size of the file, could be a few minutes.

Hope that helps.

Yeah. Thanks. I went through with option 1, and then programmed it to move the file if they accepted the preview. That way it’s easy to just empty out the original folder if it gets full of junk over time.

$_FILES[‘uploadedfile’][‘tmp_name’] contains absolute path.

I think without "…/tmp/ " it should works.

Hmm…well I already did it the other way. However, I’ll remember this, so if I have issues with the code I’ll redo it as you suggested. I don’t have enough experience to know which way is more “efficient,” so until I find a problem, I’ll just leave it for now. Thanks though!!!

Sponsor our Newsletter | Privacy Policy | Terms of Service