note 56121 added to function.file-exists
| From: | tma at 2p dot cz | Date: | Wed, 24 Aug 2005 08:47:59 +0000 |
| Subject: | note 56121 added to function.file-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94114@lists.php.net to get a copy of this message | ||
If checking for a file newly created by an external program in Windows then file_exists() does not
recognize it immediately. Iy seems that a short timeout may be required.
<?
$file = 'file.tmp';
if ($h = popen("start \"bla\" touch $file", "r")) {
pclose($h);
// now I would like know if a file was created
// note: usleep not supported
$start = gettimeofday();
while (!file_exists(trim($file, " '\""))) {
$stop = gettimeofday();
if ( 1000000 * ($stop['sec'] - $start['sec']) + $stop['usec']
- $start['usec'] > 500000) break; // wait a moment
}
if (file_exists($file)) // now should be reliable
?>
----
Manual Page -- http://www.php.net/manual/en/function.file-exists.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56121
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56121&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56121&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56121&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56121&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56121&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56121&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56121&report=yes
Search -- http://master.php.net/manage/user-notes.php