• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 316
  • Last Modified:

Displaying the contents of FileField in a form via PHP when redisplayed due to validation failure

In PHP when you are processing a form and don't get the right answers or have missing fields and redisplay the form using value=$_POST['fieldname'] to display the information which was entered before, how do you display the filename which was entered into a FileField?
0
Computer_Dilo
Asked:
Computer_Dilo
  • 2
1 Solution
 
hernst42Commented:
Thats not possible. The value of <input type="file"> is neither writeable via HTML nor via JS, only via user interactions. THis is due security reasons as else forms could steal files from the user without permisions of the user.
0
 
RoonaanCommented:
A solution might be to implement additional Javascript form validation, such that the missing fields are detected clientside.
Note that this should not replace your serverside validation as not everyone might have javascript enabled.

-r-
0
 
Computer_DiloAuthor Commented:
That's what I thought hernst42 - except I didn't know why exactly (thanks). So would there be another way with a normal text field used to load a file using PHP code??
0
 
hernst42Commented:
You could save the submitted file, if not all fields are filled to  a temporay location on the server, add a marker in a hidden field and if the form is resubmitted, all fields filled use the temp-file instead of the file from $_FILES. That will require that you clean up the temp-directory for leftover files, where the form has not submitted again.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now