Home / Blog / Move Files Using PHP Code

Move Files Using PHP Code

by | Feb 26, 2012 | 1 comment

Hi, Today I am going to talk about how to move files with php
There are two ways to do it.

1. Copy and Delete

First you have to copy that file you want to move to where you want and then delete the old copy.


$file = 'folder1/example.txt';
$newfile = 'folder2/example.txt';

copy($file, $newfile);

2. Using Rename Function

This one is easier than the first one.You have to give the path of the file that you want to move in the first parameter of the rename() function.
Then give the new path for the file in the second parameter (give the path with the file name).


$file = 'folder1/example.txt';
$newfile = 'folder2/example.txt';


. . .

This was originally posted on one of my old blog –

1 Comment

  1. Sajjad Hossain

    eitai valo copy er ceye!


Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Goodreads Updates

Goodreads Read Shelf

Steve Jobs
Zero to One: Notes on Startups, or How to Build the Future
The Tipping Point: How Little Things Can Make a Big Difference
The Fault in Our Stars
Harry Potter and the Sorcerer's Stone
The One Thing: The Surprisingly Simple Truth Behind Extraordinary Results
How to Win Friends and Influence People
Outliers: The Story of Success
Rich Dad, Poor Dad
The Power of Habit: Why We Do What We Do in Life and Business
Who Moved My Cheese?
Blink: The Power of Thinking Without Thinking
Good to Great: Why Some Companies Make the Leap... and Others Don't
Sapiens: A Brief History of Humankind
We Should All Be Feminists
A Brief History of Time
The Happiness Project: Or Why I Spent a Year Trying to Sing in the Morning, Clean My Closets, Fight Right, Read Aristotle, and Generally Have More Fun
What the Dog Saw and Other Adventures
Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones
David and Goliath: Underdogs, Misfits, and the Art of Battling Giants