How To Rename File Name In Php Laravel?

Hey Developer, In this blog post i say How To Rename File Name In Php Laravel?, i will see you how to rename uploaded file name in php. This blog will give you easy example of how to rename file name in php laravel. We will use how to rename file name in php laravel. We will look at example of php rename file name in folder. Let’s get started with php laravel rename file name in folder.

If you need to rename file in folder php code then we can use “rename()” function of php. php provide rename function to rename file name to you use rename() function is easy to useful healthful tips for you your file from one place to another.

So, here i will give you very simple & Easy example and syntax how it works to rename file name in folder in php laravel.

Let’s see bellow syntax and example that will help you. ??

Syntax:

bool rename( string $source, string $destination, resource $context )

You can see bellow parameter in details:

$source: need to give file path you want to rename.

$destination: need to give file path for destination source.

$context: this is an optional, only specifies the created with stream_context_create() function.

Example:

<?php

/* Existing File name */
$file_path = 'images/laralogo.png';

/* New File name */
$new_file_name = 'images/laralogo_new.png';



/* Rename Your New File name */
if( !rename($file_path, $new_file_name) ) {  
    echo "false";  
}  

else {  

    echo "true";  
} 

?>

I hope it can help you… please comment below…………..

Leave a Comment