Having a problem with paths and Firefox!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sir-Alucard
Forum Newbie
Posts: 9
Joined: Sat Oct 23, 2004 12:17 am

Having a problem with paths and Firefox!

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Post the code.
Sir-Alucard
Forum Newbie
Posts: 9
Joined: Sat Oct 23, 2004 12:17 am

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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'].
Sir-Alucard
Forum Newbie
Posts: 9
Joined: Sat Oct 23, 2004 12:17 am

Post 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>
Post Reply