Retaining input - file upload in HTML

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 ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-02-2007
Michael Daly
 
Posts: n/a
Default Retaining input - file upload in HTML

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
Reply With Quote
  #2 (permalink)  
Old 04-05-2007
Tyno Gendo
 
Posts: n/a
Default Re: Retaining input - file upload in HTML

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>
Reply With Quote
  #3 (permalink)  
Old 04-05-2007
Michael Daly
 
Posts: n/a
Default Re: Retaining input - file upload in HTML

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:51 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0