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';
}
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With