How To Copy File Or Directory In Php Scripts Code Copying Files Directories
Posted On Sat Mar 08, 2008 By hostman In PHP Forums And Topics Discussions About Hyper Text Programming Language Forums
today i was wondering if it would be possible to copy directories or file using php code..
well, you're in luck because yes it is possible.
Example Script CODE:
you can get more info at:
http://www.php.net/manual/en/function.copy.php
you can call this function with this example, lets say i want to copy my themes from my source files to my new websites i would do this:
PHP CODE
well, you're in luck because yes it is possible.
How To Copy File
Example Script CODE:
<?php
$file = 'old_file.txt';
$newfile = 'new_file.txt';
if (!copy($file, $newfile)) {
echo "failed to copy $file...n";
}
?>
$file = 'old_file.txt';
$newfile = 'new_file.txt';
if (!copy($file, $newfile)) {
echo "failed to copy $file...n";
}
?>
you can get more info at:
http://www.php.net/manual/en/function.copy.php
How to copy Directory
to copy directory you can use this handy function:function full_copy( $source, $target ) {
if ( is_dir( $source ) ) {
@mkdir( $target );
$d = dir( $source );
while ( FALSE !== ( $entry = $d->read() ) ) {
if ( $entry == '.' || $entry == '..' ) {
continue;
}
$Entry = $source . '/' . $entry;
if ( is_dir( $Entry ) ) {
full_copy( $Entry, $target . '/' . $entry );
continue;
}
copy( $Entry, $target . '/' . $entry );
}
$d->close();
}else {
copy( $source, $target );
}
}
you can call this function with this example, lets say i want to copy my themes from my source files to my new websites i would do this:
PHP CODE
$source ='/var/www/source/theme';
$destination = '/var/www/newsite/theme/';
full_copy($source, $destination)
$destination = '/var/www/newsite/theme/';
full_copy($source, $destination)
Rakesh Sun Apr 21, 2013
Very very very very thank you
I was distraught for one week ,
I got Solution On your website.
Please so how to implement as a tutorial.
Thank you so much.......
I was distraught for one week ,
I got Solution On your website.
Please so how to implement as a tutorial.
Thank you so much.......
Solomon Mon May 28, 2012
Thanks boss, much love for the code....really helped
louie Sun May 20, 2012
thanks a lot..
VINAYSINGH Thu Mar 22, 2012
nice CODE VERY GOOD TO HELPS US
gopal Mon Jan 30, 2012
thnaks a lot
this code is very useful for me
this code is very useful for me
Rahul Sun Jan 08, 2012
Thanks
i m seeking it From a long time
Thanks
i m seeking it From a long time
Thanks
Christopher Fri Dec 30, 2011
Thanks! This did what I needed it to do.
Rehan Mon Oct 17, 2011
its really helpful,
i will try this on Site..
i will try this on Site..
jony Wed Oct 12, 2011
Really awesomee.........Thnks a lot...
Victor Wed Oct 12, 2011
Will it copy the contents too?
Hammad Fri Aug 12, 2011
Thanks alot Sir...
This Code is doing work perfectly..
Thanks again..
This Code is doing work perfectly..
Thanks again..
Sumit Wed Jun 15, 2011
Great Post Friend.
You solved the problem. And the solutions is great.
You solved the problem. And the solutions is great.
John Tue May 24, 2011
Just what I needed! Works flawlessly.
Thank you so much.
Thank you so much.
ico Sat Apr 30, 2011
this is great!!!
Muhammad Thu Apr 28, 2011
You have done a good job.
Related Content
Information
Forums »
PHP Forums And Topics Discussions About Hyper Text Programming Language »
How To Copy File Or Directory In Php Scripts Code Copying Files Directories
PHP Forums And Topics Discussions About Hyper Text Programming Language »
How To Copy File Or Directory In Php Scripts Code Copying Files Directories
Title: How To Copy File Or Directory In Php Scripts Code Copying Files Directories
Description: in this post i will teach you how to copy a file or a directory using PHP with a sample script and will give you the code you can use for copying files and directories
Tags: php , copy , file , directory , script , code , tutorial , howto
Info: This Post Has Been Viewed 0 Times Since
Date: Sat Mar 08, 2008
Author hostman Received 26 Replies #1126
Date: Sat Mar 08, 2008
Author hostman Received 26 Replies #1126
Share
URL: 

Embed: 

To embed this topic, just copy the code from the "Embed" box. Once you've copied the code, just paste it into your website or blog to embed it
BBCODE:: 

BBCODE is use on forums. You can put this code on all your BBCODE enabled forums like PhpBB, vBulletin® and others. Just Copy and Paste this code on your Posts and Replies on your forums
wallpaperama | Wallpapers | Forums | Terms Of Service
copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Fri May 24, 2013 (-8 GMT)
Powered by: Webune Forums V5
copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Fri May 24, 2013 (-8 GMT)
Powered by: Webune Forums V5