★ wanayoo — archive 1999 http://fr.php.net/manual/zh/function.copy.phpNouvelle recherche | Portail wanayoo
PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<clearstatcachedelete>
view the version of this page
Last updated: Sat, 19 Feb 2005

copy

(PHP 3, PHP 4 , PHP 5)

copy -- ¿½±´Îļþ

˵Ã÷

bool copy ( string source, string dest)

½«Îļþ´Ó source ¿½±´µ½ dest¡£Èç¹û³É¹¦Ôò·µ»Ø TRUE£¬Ê§°ÜÔò·µ»Ø FALSE¡£

Àý×Ó 1. copy() Àý×Ó

<?php
if (!copy($file, $file.'.bak')) {
   print (
"failed to copy $file...<br>\n");
}
?>

×¢: ´Ó PHP 4.3.0 ¿ªÊ¼£¬Èç¹ûÆôÓÃÁË¡°fopen wrappers¡±µÄ»°£¬source ºÍ dest ¶¼¿ÉÒÔÊÇ URL¡£¸ü¶àϸ½Ú¼û fopen()¡£Èç¹û dest ÊÇÒ»¸ö URL£¬ÔòÈç¹û·âװЭÒé²»Ö§³Ö¸²¸ÇÒÑÓеÄÎļþʱ¿½±´²Ù×÷»áʧ°Ü¡£

¾¯¸æ

Èç¹ûÄ¿±êÎļþÒÑ´æÔÚ£¬½«»á±»¸²¸Ç¡£

²Î¼û move_uploaded_file()£¬rename() ºÍÊÖ²áÖйØÓÚÎļþÉÏ´«´¦ÀíÒ»½Ú¡£



add a note add a note User Contributed Notes
copy
info at sameprecision dot org
29-Jan-2005 12:54
When using copy on win32 (don't know about anywhere else),  copy sets the 'last modified time' of the the new copy to the current time instead of that of the source (win32 copy preserves last modified time).  If you are tracking backups by last modified time, use:

<?php

copy
($src, $dest); touch($dest, filemtime($src));

?>
20-Jan-2005 01:34
Heres a quick function I wrote to backup whole websites.
I haven't actually tested it out yet. I will later on  =P
<?

function backup($extension) {
  
$counter = 0;
   foreach(
glob(*. “$extension”) as $file) {
       if (
$extension{0} != .) {
          
$extension = .. $extension;
       }
      
$file2 = ./backup/. “$file”;
      
$counter++;
      
copy($file, $file2);
   }
   if (
$counter == 0) {
       return
false;
   } else {
       return
true;
   }
}

/* Test -- Copy all images */

$extension_array = array(.jpg”, .gif”, .png”, .bmp”);

foreach(
$extension_array as $key => $value) {
  
backup($extension);
}

?>
simonr_at_orangutan_dot_co_dot_uk
03-Sep-2004 10:54
Having spent hours tacking down a copy() error: Permission denied , (and duly worrying about chmod on winXP) , its worth pointing out that the 'destination' needs to contain the actual file name ! --- NOT just the path to the folder you wish to copy into.......
DOH !
hope this saves somebody hours of fruitless debugging
aidan at php dot net
30-Aug-2004 09:29
If you want to copy a file, or an entire folder (including the contents), use the below function.

http://aidan.dotgeek.org/lib/?file=function.copyr.php
kadnan at yahoo dot com
30-Aug-2004 07:30
you can also try xcopy command by using Shell to move/copy files/folders from one place to another
here is the code:

<?php
exec
('xcopy c:\\myfolder d:\\myfolder /e/i', $a, $a1);
?>

by executing this command, it will move folder along with all contents to destination.

-adnan

<clearstatcachedelete>
 Last updated: Sat, 19 Feb 2005
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This mirror generously provided by: nexen.net
Last updated: Mon Feb 21 05:12:00 2005 CET