cross

Move Files With PHP

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.

Example:

<?php
	$file = 'folder1/example.txt';
	$newfile = 'folder2/example.txt';
	
	copy($file, $newfile);
	unlink(file); 
?>

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 and give the new path for the file in the second parameter (give the path with the file name).

Example:

<?php
	$file = 'folder1/example.txt';
	$newfile = 'folder2/example.txt';
	
	rename($file,$newfile);
?>

One thought on “Move Files With PHP

  1. eitai valo copy er ceye!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Advertisement

Tweets