This post will give you example of move a file from one folder to another folder in php. i explained simply about how to move file from one folder to another in php. we will help you to give example of php move file example. Here you will learn php move file from one folder to another.
If you need to move file from one folder to another using php code then we can use "rename()" function of php. php provide move function to move your file from one place to another.
So, here i will give you very simple example and syntax how it works to move file from one folder to another in php.
Let's see bellow syntax and example that will help you.
Syntax:
bool move( string $source, string $destination, resource $context )
You can see bellow parameter in details:
$source: you need to give file path that you want to copy.
$destination: you need to give file path for destination source.
$context: this is optional, It specifies the context resource created with stream_context_create() function.
Example:
<?php
/* Store the path of source file */
$filePath = 'images/test.jpeg';
/* Store the path of destination file */
$destinationFilePath = 'copyImages/test.jpeg';
/* Copy File from images to copyImages folder */
if( !rename($filePath, $destinationFilePath) ) {
echo "File can't be moved!";
}
else {
echo "File has been moved!";
}
?>
I hope it can help you...
Do you like below Tutorials ?
- Laravel 7.x and 6.x Ajax Multiple Image Upload with Preview Example
- Laravel select with count(*) using db raw example
- PHP Laravel select with join subquery example
- PHP Laravel Ajax Form Submit Example
- How to create events for created/updated/deleted model task in Laravel 5?
- Angular JS Form Validation Example Code
- AngularJS - Confirm Password Validation Example
- Laravel Ajax Request using X-editable bootstrap Plugin Example