Home > Archive > PHP Language > April 2007 > Retaining input - file upload in HTML
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Retaining input - file upload in HTML
|
|
| Michael Daly 2007-04-02, 6:58 pm |
| 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
| |
| Tyno Gendo 2007-04-04, 10:00 pm |
| 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="java script: 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>
| |
| Michael Daly 2007-04-04, 10:00 pm |
| 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
|
|
|
|
|