php

PHP Copying, Renaming and Deleting a file


 

PHP provides a variety of functions and features for interacting with the file system like copying, renaming and deleting a file. Here's a brief overview of the opertions can be performed in PHP:

 

PHP COPY():

The copy() function is used to copy a file in PHP.

Syntax:

<?php
    	copy($sourceFilePath, $destinationFilePath);
	?>

 

Example:

<?php
    	$sourceFile = 'path/sourceFile.php';
    	$destinationFile = 'path/destinationFile.php';

	
    	copy($sourceFile, $destinationFile);
	?>

 

PHP RENAME():

The rename() function is used to rename a file in PHP.

 

Syntax:

<?php
    	rename($oldFilePath, $newFilePath);
	?>

 

Example:

<?php
    	$oldFilePath = '/oldPath/file.php';
    	$newFilePath = '/newPath/file.php';
    
	
    	rename($oldFilePath, $newFilePath);
	?>

 

PHP UNLINK():

The unlink() function is used to delete a file in PHP.

 

Syntax:

    <?php
        bool unlink ( string $filename [, resource $context ] )  
    ?>

 

Example:

<?php
    	unlink('test.php');
	?>

 

PHP File System allows us to create file, read file line by line, read file character by character, write file, append file, delete file and close file.