PHP Populate input type=file field from stored value

When there is an error on the form I add the values back in the fields so the user doesn't have to renenter them.  All fields work fine except my file field.   I tried something like this:

<input type="file" name="file" id="file"  value="<?php if (isset($_FILES["file"]["tmp_name"])) echo $_FILES["file"]["tmp_name"]; ?>" />

Open in new window

That didn't seem to work.


Who is Participating?
GaryConnect With a Mentor Commented:
You can't, it's a security measure, otherwise someone could lift any file from your pc.
What you could is store the file on first postback ready for when they have made corrections and posted again so they don't have to set the file again and just let them know you already have the file.
Dave BaldwinFixer of ProblemsCommented:
Gary's right, you can't preset a 'file' field.  That is to prevent someone from loading one of your files against your will.
Ray PaseurCommented:
What GaryC123 and DaveBaldwin said.  No points for this answer, please, but consider the implications if a server-side script could read anything it wanted from your PC.  If you figure out a way to prepopulate the contents of $_FILES the security experts will shut your method down as quickly as they can find it.  Don't build an application that needs to rely on this kind of security hole.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.