Jump to content

Change Default Value of HTML FileUpload Object


lazycrane

Recommended Posts

Hi, I am new to PHP and am having trouble changing the default value of an HTML FileUpload Object. I googled this problem and it seems that the only way to do this is by using JavaScript. Ideally I would like to avoid using the latter, because the form which contains this object, is being created dynamically within php braces

echo"<td> <input type=\"file\" name=\"pics1\"></td>";

and therefore adding JavaScript to the whole thing might makes things a bit nasty. Can anyone suggest a PHP solution or some work-around for this problem. Thanks in advance for any help or suggestions  :).

 

Alex

well what ever you call the file input field it will be available in the $_FILES array in the next page.

 

so if you simply grab the field name in the accpeting script you can do what ever you like.

 

$name = array_keys($_FILES);

$name = $name[0];

 

that should giv you your dynamic input name.

Thanks for your reply :), however the problem is I need to change this value as soon as the FileUpload Object is created. Since this html object's value attribute is readonly and the defaultValue attribute cannot be accessed directly through html, I think some sort of workaround is necessary  :-\.

 

Alex

????

 

that makes no sense at all...

 

the name attribute of the input can be what ever you like - and its only use is in the $_FILES array in the next script.  this is a super global so instead of trying to change it just use it.

 

before you can change something you need to know what it is first....

 

alternatively do you mean you wish to change the actual filename - like me.gif to xyz.gif?

 

if so you can change the filename when using he move_uploaded_file function...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.