note 15555 deleted from function.file-exists by jimw

From: Date: Wed, 02 Jan 2002 01:02:12 +0000
Subject: note 15555 deleted from function.file-exists by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-24082@lists.php.net to get a copy of this message
This function caused me tons of headaches. It doesn't appear to return a 1 on large files such as a few Gigs in my case. file_exists("/www/logs/20010917.log") returns 0 ll /www/logs/20010917.log shows up with a file size of 7.2G. Therefore, I came to the conclusion file_exists actually opens the file. I don't really need this to happen on a 7.2G file. Therefore I came up with the following function. **************************************** function file_does_exist($file_name) { $split = explode("/", $file_name); $dir = ""; for ($x = 1; $x <= sizeof($split); $x++) { if ($split[$x] > "") { $dir .= "/$split[$x]"; $short_file_name = $split[$x]; } } $dir = ereg_replace($short_file_name, "", $dir); $file = $short_file_name; $d = dir($dir); while ($entry = $d->read()) { if ($short_file_name == $entry) { $return_val = 1; break; } else { $return_val = 0; } } $d->close(); return $return_val; } **************************************** What this function basically does is a directory listing and compares it to the filename. Hope this helps someone. sglane http://www.scriptsharks.com/

« previous php.notes (#24082) next »