Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i detect if php rename() has been successfully executed?

Tags:

php

rename

The php docs say that the following will return true if successful or false if it fails.

rename('test/test1/','test/test2/test1/');

How do I get the true or false? If I run the exact function and it's succesful, the folder gets moved as hoped and there is no output. If it fails, then it just prints out an error message.

How do I test if true or false so that I can tell if the rename function succeeded, without the error message?

Is this the correct way?

error_reporting(0);
if(rename('test/test1/','test/test1/test2/test1/')===true){
   print 'true';
} else{
   print 'false';
}
like image 678
jon Avatar asked Dec 12 '22 05:12

jon


1 Answers

You would simply do this to get the return value:

$success = rename($oldValue, $newValue);

You can then do whatever you need to with the value of $success.

like image 114
Brian Driscoll Avatar answered May 17 '23 16:05

Brian Driscoll