lazycrane Posted June 8, 2007 Share Posted June 8, 2007 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 Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted June 8, 2007 Share Posted June 8, 2007 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. Quote Link to comment Share on other sites More sharing options...
lazycrane Posted June 8, 2007 Author Share Posted June 8, 2007 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 Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted June 8, 2007 Share Posted June 8, 2007 ???? 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... Quote Link to comment Share on other sites More sharing options...
lazycrane Posted June 8, 2007 Author Share Posted June 8, 2007 hmm yes I was referring to the filename (the value of the FileUpload Object not its name). Is it possible to place a value within the said object as soon as it is created (before the user has made use of it)? Thanks Alex Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.