You are here: Re: Help with loop « PHP Programming Language « IT news, forums, messages
Re: Help with loop

Posted by Janwillem Borleffs on 09/30/06 16:24

Scoop wrote:
> Can someone tell me what I'm doing wrong?
>

You're using the wrong function to check if the file exists and you are not
preventing an infinite loop. Try running the following code:

<?php
$file = 'somefile';
$currentdir = '';
$found = false;
while (true) {
// Check if file exists
if ($found = file_exists($file)) {
break;
}

// Prevent infinite loop
if ($currentdir == realpath(dirname($file))) {
break;
}

// Update paths
$file = "../$file";
$currentdir = realpath(dirname($file));
}

// Show result
echo basename($file),
$found ?
" found under: " . realpath(dirname($file)) :
" not found";
?>


HTH;
JW

 

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

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