Reply to Re: Retaining input - file upload in HTML

Your name:

Reply:


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>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация