Shinu Thomas
Shinu Thomas

Reputation: 5316

copy a file from one dir to another dir

How i can copy one file from one directory to another directory using php

Upvotes: 1

Views: 1870

Answers (4)

Hans
Hans

Reputation: 3523

If you are moving a file just uploaded, use http://php.net/manual/en/function.move-uploaded-file.php instead of rename(). It gives you some added security.

Upvotes: 0

Gordon
Gordon

Reputation: 317217

You can use

  • copy — Copies file

Example from Manual:

$file = 'example.txt';
$newfile = 'example.txt.bak';

if (!copy($file, $newfile)) {
    echo "failed to copy $file...\n";
}

Upvotes: 6

Alex Pliutau
Alex Pliutau

Reputation: 21947

rename('path/to/file/file.ext', 'path2/to2/file2/file.ext');

Upvotes: 3

Pekka
Pekka

Reputation: 449843

Use rename().

rename ("/var/www/files/file.txt", "/var/www/sites/file.txt");

Upvotes: 5

Related Questions