tags:

views:

23

answers:

3

Ok so i have a html form, 10 files get uploaded. 6 images and 4 pdf. some of theses files are required others not.

My problem is when my script verifys the data and retuns to the user that he/she has errors all the file inputs are come back as blank... and if the user re-submitts... the files are not saved.

This form has other fields other than the files as well.

I tried putting $_POST in the value of my inputs but that does not repopulate with the local file names.

I would like it so my users dont need to re enter all the files they want to upload if they made 1 or a few mistakes.

edited: SO is this normal that the post isnt giving me the file name? is the file still saved as temp on the server?

A: 

Make sure to specify proper settings for:

  • file_uploads
  • upload_max_filesize
  • memory_limit
  • max_execution_time
  • post_max_size

See:

Also make sure that:

  • You have specified the enctype="multipart" in the form
  • Check the files array with print_r($_FILES);
Sarfraz
my settings should be all ok. everything works if the user doesnt make any mistakes. but if there is 1 miustake the page reloads. is there a way to obtain the local file path and file name so that if they do a mistake they dont have to refill the form.
StiGMaT
my print_r on the first post submits the file names and data the send i correct my mistakes and re-submit no images come out.
StiGMaT
You can get the name from `$_FILES['fieldName']['name']`
Sarfraz
A: 

Instead of redirecting them back to form use a bit of JavaScript and make client browser to go one page back. Then he should file that were selected before.
You could use something like:

<body onLoad="javascript:history.go(-1)">...</body>
Semas
A: 

The value attribute of the file input type doesn't exist as this is a security risk. You can't read it or set the value of it (client or server side) so even if you had the local path on the user's computer you couldn't fill it in.

I would try to do some sort of client side (even through ajax) form validation before they submit the form. If they do submit the form, the files will upload and should still be in the temp directory (at least until garbage collection kicks in). Maybe on error write the information in $_FILES to session and instead of showing the file upload dialog, show an icon for the file to try to let them know you got the file, but they need to fix the form for everything to finish. Then after they submit the corrections you can get the data from the session and try to continue.

Jonathan Kuhn
ya ive been looking for an answer all day and this pretty much looks like the way to go. so i started adding javascript validation before its sent to the sever.
StiGMaT