Cannot echo value in file field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Cannot echo value in file field

Post by thomas777neo »

I cant seem to show an initial value in a file field:

Code: Select all

<input name="example" type="file" id="example" value="thomas" />
Is there anyway around it?
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

Unfortunately most browsers don't support prepopulating the value of a file input field. I think its for security reasons.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

Skittlewidth wrote:Unfortunately most browsers don't support prepopulating the value of a file input field. I think its for security reasons.
since when? ive been doing this for years now, never noticed any problems
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post by thomas777neo »

That sucks, oh well
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

malcolmboston wrote: since when? ive been doing this for years now, never noticed any problems
Really? How? I was trying to do it a few months back on an edit form and I couldn't get it to work. I googled the problem and other people said it couldn't be done.

I ended up having to echo to the user what their previous attached file was above the file input field instead.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

what browser are you testing this on?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Re: Cannot echo value in file field

Post by malcolmboston »

well i would just do something like:

Code: Select all

<input name="example" type="file" id="example" value="<?php print $value; ?>">
i know for a certainty this works on at least the following on my home computer:

IE 5.5
IE 6
Firefox (god knows what version)
Opera 7
Opera 8
Mozilla (Unknown)

all versions are relatively new
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Re: Cannot echo value in file field

Post by foobar »

malcolmboston wrote:well i would just do something like:

Code: Select all

<input name="example" type="file" id="example" value="<?php print $value; ?>">
i know for a certainty this works on at least the following on my home computer:

IE 5.5
IE 6
Firefox (god knows what version)
Opera 7
Opera 8
Mozilla (Unknown)

all versions are relatively new
That's odd. That's a huge security issue. You could upload the user's users.dat or system.dat that way (or anything else for that matter)! 8O

/goes and tries to do it
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

lol, just noticed this is an file input box, have never tried it with one of them :roll:
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

malcolmboston wrote:lol, just noticed this is an file input box, have never tried it with one of them :roll:
YOU.....! :evil:
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

pmsl :lol:
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

Phew! You had my confidence shaken there for a bit!
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

had me miffed too :)
Post Reply