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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

????

 

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.