473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Retain File Upload Field Data

Hello fellow PHPers,

I am relatively new to PHP but have come a long way in a short time and consider myself a fast learner. My application requires the user to enter information into forms on a website. One form requires the user to upload two or more files on the same form along with text information and check boxes. Should the user encounter an error I have designed the form to echo the posted values along with appropriate error messages. My challenge is how to echo the previously selected files in the file fields on my form when the form reloads with error messages. I have the text fields and check boxes behaving accordingly but cannot figure how to retain the valid data in the file fields.

Any assistance will be greatly appreciated and will earn naming rights for my next recipe.

Regards,
Teerock.
Jul 27 '07 #1
5 2961
pbmods
5,821 Expert 4TB
Heya, Teerock. Welcome to TSDN!

You can save the value of $_FILES[]['tmp_name'] into the $_SESSION.

Alternatively, you can move_uploaded_file() each file into a User-specific directory (e.g., '/var/uploads/{userid}/').
Jul 27 '07 #2
kovik
1,044 Expert 1GB
You can save the value of $_FILES[]['tmp_name'] into the $_SESSION.
Actually, you would probably which to save $_FILES[]['name'], as it would be the filename of the original file. The 'tmp_name' index contains the temporary file's name, which will look like complete nonsense to the user.

Since you do both uploads on the same form, using a session would be wasteful. Upon failure, just print $_FILES['fieldName']['name'] in the error message for the appropriate field.
Jul 27 '07 #3
pbmods
5,821 Expert 4TB
Forgot to mention, you'll want to use the name of the file input as the primary index in $_FILES.

E.g., if your file input looks like this:
Expand|Select|Wrap|Line Numbers
  1. <input name="theFile" type="file" ... />
  2.  
Then you would access $_FILES['theFile'].
Jul 27 '07 #4
Jankie
58
Am a newbie but from my modest knowledge so far,you cannot retain selected files upon reload .

This is because they are not under your immediate control as the rest of the inputs;they are still in the users' local directory(which for security reasons you cannot have fair access to manipulate them).
On a positive note,it is possible that you can store the name of the file,hide it and redisplay it on reload using javascript.

It'll be a learning surprise to me if it can be done with php.
You mentioned "retain upload data",then "echo previously selected files" . I built my response assuming the former.If you meant just echoing file names(not data),then it can be done with sessions as suggested to you above.
Sorry if I have misunderstood you !
Jul 27 '07 #5
pbmods
5,821 Expert 4TB
Heya, Teerock.

I apologize; I misunderstood your intentions.

You cannot set the value of a file input.

(can you imagine the chaos that would ensue if websites could set the value of a file input to any file on your hard drive and then immediately submit the form?)

But the good news is, once a User uploads a file once, he no longer has to upload it again!

If any of the files are valid, but the rest of the form is not, you can retain the uploaded files, and only require that the User fix the other data.
Jul 27 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Karen Grube | last post by:
Hi! Each week, we receive a two-page PDF file from UPS along with a separate flat file (a CSV) The PDF file contains the overview of our weekly invoice and the CSV contains the details of each...
5
by: Codeman II | last post by:
Hi there, I am building a form where the user must upload a picture and fill in his details. Now I have a problem as all of this is on the same form. How will I be able to have the Browse...
2
by: Terry Field | last post by:
We've recently moved an application from a W2K server to a Windows 2003 server with IIS 6.0 and in the process managed to lose the ability to handle file uploads. I've managed to identify that this...
6
by: tshad | last post by:
I have an upload file input as: <input id="MyFile" style="width:300px" type="File" runat="Server"> This works fine, but I find that if my page doesn't pass validation during postback, the page...
2
by: yonthebeach | last post by:
hi, i have an upload mechanism on my website and want to check the filesize on the client size. is this possible? thanks yavuz bogazci
3
acoder
by: acoder | last post by:
How to Upload a File in Coldfusion Use the cffile tag for uploading files to the server. Note that allowing people to upload files is fraught with danger and only trusted users should be...
2
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
2
by: hotflash | last post by:
Hi Master CroCrew, I found a good PURE ASP that will allow you to upload 10MB file to the server and the file contents such as Network, Author, Title, etc... will insert to MS Access at the same...
1
by: ririe | last post by:
Hi. I have a problem here. I want to upload a file together with its semester. So I create two field. One for the semester and one for the file to be uploaded. But the script doesn't work. I don't...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.