You are here: Re: [PHP] is_dir & is_file bugs? « PHP « IT news, forums, messages
Re: [PHP] is_dir & is_file bugs?

Posted by M. Sokolewicz on 02/09/05 00:03

Matt M. wrote:
>> $path = 'product_images';
>> $handle = opendir($path);
>> while (false !== ($file = readdir($handle)))
>> {
>> if ($file != "." && $file != "..")
>> {
>>echo $file;
>> if (is_dir($file))
>> {
>> echo ' <-- folder<br>';
>> $folders[] = $file;
>> }
>> elseif (is_file($file))
>> {
>> echo ' <-- image<br>';
>> $images[] = $file;
>> }
>> else
>> {
>> echo ' <-- ???<br>';
>> }
>> }
>> }
>
>
> try the absolute path in is_dir and is_file
or at least the correct one.
Right now, what's hapenning is this:

imagine you have this layout:
/
/product_images/
/product_images/dir1/
/product_images/file1.ext

What your script is doing:
$handle = opendir($path);
while (false !== ($file = readdir($handle)))
{
// $file = '.' // on first run
// $file = '..' // on 2nd run
// $file = 'dir1' // on 3rd run
// $file = 'file1.ext' // on 4th run

if ($file != "." && $file != "..")
{
echo $file;
if (is_dir($file)) // it's not, since that file doesn't
exist in the place PHP is looking for it.
// because, does ./dir1/ exist? no! does ./product_images/dir1/
exist? yes!
// But that's not what you're checking ;)
{
echo ' <-- folder<br>';
$folders[] = $file;
}
elseif (is_file($file))
// same thing as with is_dir()
{
echo ' <-- image<br>';
$images[] = $file;
}
else
{
echo ' <-- ???<br>';
}
}
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация