|
Posted by Tyno Gendo on 04/05/07 00:28
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>
Navigation:
[Reply to this message]
|