Suchy Posted April 28, 2007 Share Posted April 28, 2007 I have a simple script to rename files. <?php $path = 'fotki_upload'; $dir_handle = opendir($path); while ($file = readdir($dir_handle)) rename($file, strtoupper($file)); closedir($dir_handle); ?> But I am getting these errors. Warning: rename(wixa.jpg,WIXA.JPG) [function.rename]: No such file or directory in /home/suchygn/public_html/media/fotka/rename.php on line 9 Warning: rename(.,.) [function.rename]: Device or resource busy in /home/suchygn/public_html/media/fotka/rename.php on line 9 Warning: rename(1.jpg,1.JPG) [function.rename]: No such file or directory in /home/suchygn/public_html/media/fotka/rename.php on line 9 Warning: rename(3.jpg,3.JPG) [function.rename]: No such file or directory in /home/suchygn/public_html/media/fotka/rename.php on line 9 Warning: rename(index.html,INDEX.HTML) [function.rename]: No such file or directory in /home/suchygn/public_html/media/fotka/rename.php on line 9 Warning: rename(..,..) [function.rename]: Device or resource busy in /home/suchygn/public_html/media/fotka/rename.php on line 9 What seems to be the problem, the direcotry where the files are i chomed to 777. Link to comment https://forums.phpfreaks.com/topic/49086-solved-rename-function-error/ Share on other sites More sharing options...
neel_basu Posted April 28, 2007 Share Posted April 28, 2007 The problem is not in rename(). The file/directory you are trying to access is not there its in some other location. Try chdir($path); just after opendir() and after your job is done add chdir('../'); or something like that at the end. Link to comment https://forums.phpfreaks.com/topic/49086-solved-rename-function-error/#findComment-240493 Share on other sites More sharing options...
neel_basu Posted April 28, 2007 Share Posted April 28, 2007 Or try rename($path./.$file, strtoupper($file)); Link to comment https://forums.phpfreaks.com/topic/49086-solved-rename-function-error/#findComment-240494 Share on other sites More sharing options...
ignace Posted April 28, 2007 Share Posted April 28, 2007 // The mistake you make, is very common // you forgot to include the path, because the file 1.jpg does not exist // in your current directory, but it exists in your upload_folder/1.jpg while ($file = readdir($dir_handle)) { if ($file <> "." && $file <> "..") { $full = $path . DIRECTORY_SEPERATOR . $file; rename($full, strtoupper($full)); } } Link to comment https://forums.phpfreaks.com/topic/49086-solved-rename-function-error/#findComment-240495 Share on other sites More sharing options...
ignace Posted April 28, 2007 Share Posted April 28, 2007 if it says that DIRECTORY_SEPERATOR does not exist, then add the following code just above that snippet: (normally it is implemented into php) define('DIRECTORY_SEPERATOR', (substr(PHP_OS, 0, 3) == 'WIN') ? "\\" : "/")); Link to comment https://forums.phpfreaks.com/topic/49086-solved-rename-function-error/#findComment-240498 Share on other sites More sharing options...
Suchy Posted April 28, 2007 Author Share Posted April 28, 2007 Thanks Link to comment https://forums.phpfreaks.com/topic/49086-solved-rename-function-error/#findComment-240517 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.