Page 1 of 1

Having a problem with paths and Firefox!

Posted: Thu Nov 04, 2004 10:18 pm
by Sir-Alucard
Hi, im having a problem uploading my files from a form with firefox. It works well in IE but when I use firefox and I try to read the variable that "retains" the path and the name of the file to be uploaded, it just gives me the filename without the path. So I actually cant upload the file, because the browser then doesnt knows from where to upload the file.

I've tried realpath() but it returns an empty string and dirname() but it returns a dot.

Can anybody help me here?
Thanks in advance.

Posted: Thu Nov 04, 2004 11:10 pm
by Weirdan
Post the code.

Posted: Thu Nov 04, 2004 11:48 pm
by Sir-Alucard
This example code have the same result:

Code: Select all

<html>
<head>
<title>Test</title>
</head>

<body>

<?php

if(isset($_POST&#1111;'send'])) &#123; 
	if(!empty($_POST&#1111;'archivo']&#1111;0]))&#123;
		$archivo = $_POST&#1111;'archivo']&#1111;0];
		echo $archivo."<br />";
		echo realpath($archivo)."<br />";
		echo dirname($archivo)."<br />";
	&#125;
&#125;

?>

<form action=<?php echo $_SERVER&#1111;'PHP_SELF'] ?> method=post enctype="application/x-www-form-urlencoded" >
<input type="file" name="archivo&#1111;]" /><br />
<input type="submit" name="send" value="Send" />
</form>

</body>
</html>
Using IE my output is:
C:\www\webroot\filename.ext
C:\www\webroot\filename.ext
C:\www\webroot

Using Mozilla Firefox my output is:
filename.ext

.

Hope that that makes myself clear. Thanks for any help.

Posted: Fri Nov 05, 2004 12:34 am
by Weirdan
you can add hidden field to the form and associate a js handler with onchange handler of file field like this:

Code: Select all

//..........
<input type="file" name="archivo&#1111;]" onchange="javascript:getElementById('ar').value=this.value" /><br />
<input type="text" name="arch&#1111;]" id="ar" /> <br />
//..........
and than use the $_POST['arch'] variable instead of $_POST['archivo'].

Posted: Fri Nov 05, 2004 8:44 am
by Sir-Alucard
Thanks that worked very well... in your exaple I just changed the type of "text" by "hidden" like you said:

Code: Select all

<html>
<head>
<title>Test</title>
</head>

<body>

<?php

if(isset($_POST&#1111;'send'])) &#123; 
	if(!empty($_POST&#1111;'archivo']&#1111;0]))&#123;
		$archivo = $_POST&#1111;'archivo']&#1111;0];
		echo $archivo."<br />";
		echo realpath($archivo)."<br />";
		echo dirname($archivo)."<br />";
	&#125;
&#125;

?>

<form action=<?php echo $_SERVER&#1111;'PHP_SELF'] ?> method=post enctype="application/x-www-form-urlencoded" >
<input type="file" name="arch&#1111;]" onchange="javascript:getElementById('ar').value=this.value" /><br /> 
<input type="hidden" name="archivo&#1111;]" id="ar" /> <br />
<input type="submit" name="send" value="Send" />
</form>

</body>
</html>