Click to See Complete Forum and Search --> : Problem with JavaScript and Fileupload


mm00
09-05-2002, 12:30 PM
Hi...

I'm not sure if anyone here can help me, but I'll try anyway. ;)

In short, my problem is follows:
<HTML>
<HEAD>
<script language="JavaScript">
<!--
function FileUpload()
{
document.form1.fileselect.click();
}
//-->
</script>
</HEAD>
<BODY>
<form name="form1" action="action.php" method="post" enctype="multipart/form-data">
<img src="imgview.php?filename=$filename" onClick="FileUpload()">
<input type=file size=25 maxlength=500000 name="fileselect" accept="image/*">
<input type=submit name="OKbutton" value="OK">
</form>
</BODY>
</HTML>

Now, if I click on the image, the file selection appears, I can select the file, and it appears in the input. But, once I click OK, all it does is to clear the file selection. If I chose the file manually by clicking on "Browse..." and then press the OK button, the file is sent to the action.php. I noticed this behaviour in IE 6. Mozilla and Opera simply ignore the Javascript completely.

Any suggestions on why the submit button only clears the input field, and how to fix this?

Thank you.


Marc

chingwaah
09-13-2002, 04:18 AM
I don't know what "
<img src="imgview.php?filename=$filename" onClick="FileUpload()"> " suppose to do.

When you use <INPUT type="file"...> the client browser will upload the selected file to the server, to a temporary directory. All you do is to find where this information is at so you can copy the file to your permanent directory.

PHP provide this information for you.via $_FILE array.

Example:

To copy your file to permanent directory, just use

move_uploaded_file($_FILES['fileselect']['tmp_name'], "mydirectory/myimg.gif");


Good luck!

Visit me at http://www.bringitlive.com

bealers
09-13-2002, 07:30 PM
Hmm just had a quick look here:
<http://developer.netscape.com/docs/manuals/js/client/jsref/index.htm>
and could't see fileSelect, is this IE specific? Is click() a valid method?

--
;D

chingwaah
09-13-2002, 08:10 PM
Look at the original message. There you'll find "fileselect" as a name of a field in the hform.

Hopes this clarafies it.

http://www.bringitlive.com

PS: it helps to read thoughly. :)

bealers
09-14-2002, 04:13 AM
Thanks for the patronising tone, do you practice that?