This is a discussion on Retaining input - file upload in HTML within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I have a problem that someone must have faced before. I need to allow a file upload and retain the ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have a problem that someone must have faced before.
I need to allow a file upload and retain the path and name of the file as provided by the user. However, that info is not passed by the browser to PHP. The name alone is not enough and the temp path is useless in this context. Are there any convenient workarounds? Mike |
|
|||
|
Michael Daly wrote:
> I have a problem that someone must have faced before. > > I need to allow a file upload and retain the path and name of the file > as provided by the user. However, that info is not passed by the > browser to PHP. The name alone is not enough and the temp path is > useless in this context. Are there any convenient workarounds? > > Mike There may be another way, but I've never tried before, so here is something I knocked up quickly that will do what you want as long as you don't mind some 'javascript' 'onsubmit' of the form. It takes the local directory/filename from the file input box before submission and copies it into a hidden input, which you can then read on the PHP side. <?php if ($_SERVER["REQUEST_METHOD"]=="POST") { echo $_POST["localfile"]; } ?> <form action="index.php" method="post" enctype="multipart/form-data" onsubmit="javascript: document.getElementById('localfile').value = document.getElementById('myfile').value; return true;"> <input type="file" id="myfile" name="myfile" value="" /> <input type="hidden" id="localfile" name="localfile" value="" /> <input type="submit" /> </form> |
|
|||
|
Tyno Gendo wrote:
> There may be another way, but I've never tried before, so here is > something I knocked up quickly that will do what you want as long as you > don't mind some 'javascript' 'onsubmit' of the form. Thanks! I'll use this. I haven't found anything other than another Javascript example very much like yours (though yours is simpler). From what I've read, it seems that a client-side approach is the only way to do this. Mike |