1

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

0

4 Answers 4

6

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"; } 
Sign up to request clarification or add additional context in comments.

Comments

5

Use rename().

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

2 Comments

it is working fine.But it is deleted from the source i Want it in the source also
@THOmas you are asking to move it in the question title, and copy in the question body... To copy it, use copy()
3
rename('path/to/file/file.ext', 'path2/to2/file2/file.ext'); 

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.