PHP 8.5.0 Alpha 4 available for testing

Voting

: three plus six?
(Example: nine)

The Note You're Voting On

Robert
11 years ago
If you use SplFileObject for the same file which
you want to rename you have to remove SplFileObject objec first.

<?php

$filePath
= 'testFile.txt';
$fileObj = new SplFileObject( $filePath );
rename( $filePath, 'newName.txt' );

// You will get - Permission denied error

$filePath = 'testFile.txt';
$fileObj = new SplFileObject( 'filePath.txt' );
$fileObj = null;
rename( $filePath, 'newName.txt' );

// and now it is working.
?>

<< Back to user notes page

To Top