|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-09-03 17:02 UTC] david at grudl dot com
Description: ------------ Renaming of non-existent file generates in PHP 5.2.6 warning: Warning: rename(foo,bar) [function.rename]: No such file or directory And in PHP 5.3.0 alpha2 it generates warning: Warning: rename(foo,bar): Bad file descriptor I am not sure, but maybe this points to any hidden bug in renaming routine... PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 22:00:02 2025 UTC |
I also observe this issue in multiple Windows OS'. Below is the offending code: echo "Modifying $file\n"; $currentFile = str_replace("c:","C:",$testFileDirectory) . "\\" . $file; $fh = fopen($currentFile, 'r') or die("can't open the original file"); $tmpfile = getcwd() . "\\temp\\" . rand(); $fp = fopen($tmpfile, 'a') or die("can't open tmp file"); $temporaryString = ""; while ($tmpStringData = fread($fh,1024)) { $stringLength = mb_strlen($tmpStringData); $coinFlip = rand(0,1); switch ($coinFlip) { case 0: while (mb_strlen($temporaryString) < $stringLength) { $temporaryString = $temporaryString . rand(0,9); } fwrite($fp,$temporaryString); break; case 1: fwrite($fp,$tmpStringData); break; }//end switch }//end while fclose($fh); fclose($fp); rename($tmpfile,$currentFile) or die("Unable to rename the tmp file."); $fileToMD5 = getCWD() . str_replace("c:","C:",$testFileDirectory) . "\\"; addMD5($currentFile); The error occurs during the rename() after fclose(). It seems that the file is locked or otherwise prevented from being renamed. Perhaps fclose() is lagging somehow? I have verified that the file does, in fact, exist when this issue occurs.