PDA

View Full Version : PHP - having trouble with path


pixelvoodoo22
03-07-2010, 09:27 AM
Hi,

A real simple one for anyone who understands php I should imagine.

This script I found works perfectly. I make a call to the php, and it returns some xml to tell me all files within the folder it lives in.

What I'm trying to do is have this script in a different folder to my images. So I'm changing the opendir bit to "images" or "/images" or "../images" or "images/" and nothing works at all! is there something I'm missing? A special way to write the path out of where the php is sitting, or another line I need to change in the php?

It's driving me mad, any help appreciated!
Thanks


<?php
$xml = '<?xml version="1.0"?'.'><images>';
$dir = opendir(".");
while ( ($file=readdir($dir)) !== false ) {

if ( !is_dir($file) ){

$pic = @getimagesize($file);

if($pic != false && $pic[2] == 2){
$xml .= '<img src="'.$file.'" width="'.$pic[0].'" height="'.$pic[1].'" />';
}
}
}

$xml .= '</images>';
echo $xml;
?>

wyattbiker
03-08-2010, 01:37 PM
You are not providing enough information. If you want to use the relative paths . or .. or directoryname then tell us where your images folder is in relation to the php file.

Try entering the absolute physical path and see if that works. E.g. /myapp/images

Also on Linux/Unix and some Mac OS X systems path/filenames are case sensitive.

pixelvoodoo22
03-08-2010, 08:25 PM
The images folder lives right along side the php file, in the same directory

wyattbiker
03-09-2010, 12:45 PM
The images folder lives right along side the php file, in the same directory

try ./images but images/ or images should do it too.

../images or /images will not work unless your php file is in the virtual root folder.

Check the folder rights and use some echo's to debug.

pixelvoodoo22
03-10-2010, 07:28 AM
I've tried all of those suggestions before, nada.

I checked that the images folder was read and writable, and even tried a line in the php that created a folder itself, then added the images to that folder, but still nothing.

Weird thing is, whatever I change the "." to , whether it be "images", "./images" or anything else, it still picks up images if I have them sit along side the php file?! Like that line is making no difference. But I'm definitely replacing the php file with the one I'm editing.

not sure what to write to debug this?

Thanks

pixelvoodoo22
03-10-2010, 08:22 AM
problem solved, it was actually the line forming the xml lower down that needed some work. For anybody that may need this in the future...

<?php
$xml = '<?xml version="1.0"?'.'><images>';

$filepath = "images";

$handle = opendir($filepath);
while (false != ($file = readdir($handle))) {
$pic = @getimagesize($filepath."/".$file);
if($pic != false && $pic[2] == 2){
$xml .= '<img src="'.$filepath.'/'.$file.'" width="'.$pic[0].'" height="'.$pic[1].'" />';
}
}
$xml .= '</images>';

echo $xml;
closedir($handle);

?>