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.
Having a problem with paths and Firefox!
Moderator: General Moderators
-
Sir-Alucard
- Forum Newbie
- Posts: 9
- Joined: Sat Oct 23, 2004 12:17 am
-
Sir-Alucard
- Forum Newbie
- Posts: 9
- Joined: Sat Oct 23, 2004 12:17 am
This example code have the same result:
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.
Code: Select all
<html>
<head>
<title>Test</title>
</head>
<body>
<?php
if(isset($_POSTї'send'])) {
if(!empty($_POSTї'archivo']ї0])){
$archivo = $_POSTї'archivo']ї0];
echo $archivo."<br />";
echo realpath($archivo)."<br />";
echo dirname($archivo)."<br />";
}
}
?>
<form action=<?php echo $_SERVERї'PHP_SELF'] ?> method=post enctype="application/x-www-form-urlencoded" >
<input type="file" name="archivoї]" /><br />
<input type="submit" name="send" value="Send" />
</form>
</body>
</html>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.
you can add hidden field to the form and associate a js handler with onchange handler of file field like this:
and than use the $_POST['arch'] variable instead of $_POST['archivo'].
Code: Select all
//..........
<input type="file" name="archivoї]" onchange="javascript:getElementById('ar').value=this.value" /><br />
<input type="text" name="archї]" id="ar" /> <br />
//..........-
Sir-Alucard
- Forum Newbie
- Posts: 9
- Joined: Sat Oct 23, 2004 12:17 am
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ї'send'])) {
if(!empty($_POSTї'archivo']ї0])){
$archivo = $_POSTї'archivo']ї0];
echo $archivo."<br />";
echo realpath($archivo)."<br />";
echo dirname($archivo)."<br />";
}
}
?>
<form action=<?php echo $_SERVERї'PHP_SELF'] ?> method=post enctype="application/x-www-form-urlencoded" >
<input type="file" name="archї]" onchange="javascript:getElementById('ar').value=this.value" /><br />
<input type="hidden" name="archivoї]" id="ar" /> <br />
<input type="submit" name="send" value="Send" />
</form>
</body>
</html>