Portrety Uliczne Nieznajomych - zobacz wyjątkową galerię portretów z warszawskich ulic
ZALOGUJ SIĘ
login:
hasło:
przypomnij hasło
załóż konto użytkownika
(i zobacz kilka porad gratis)
   
WYSZUKIWARKA I DZIAŁY
całe porady  tytuły
zaznacz działy do przeszukania
(brak wyboru = wszystkie działy)
PHP
MySQL >
PostgreSQL
SQLite
Perl
Java
XML
XSLT
XPath
WML
SVG
RegExp
Wyszukiwarki
Ochrona
VBScript
Google Plus
XHTML/CSS
JavaScript
Grafika
Flash
Photoshop
Windows
Linux
Bash
Apache
Procmail
E-biznes
Explorer
Opera
Firefox
Inne porady
   
KURSY, DOKUMENTACJE
Własne:
XHTML/CSS
JavaScript
ActionScript
WML, RSS, SSI
Pozostałe:
PHP
MySQL
Java API
więcej...
   
użytkowników online: 61
W CZYM MOGĘ POMÓC?


   
OPINIE UŻYTKOWNIKÓW
Nie jestem webmasterem, ale i na mnie zrobiła wrażenie szybkość reakcji Darka na mój problem. Jego kompetencja i przede wszystkim zupełnie niemodna w dzisiejszych skomercjalizowanych czasach - zwykła ludzka życzliwość dla innego człowieka. Tacy ludzie to dziś gatunek niemal wymarły...

Leszek
Wojskowy Instytut Medyczny

   
GALERIA FOTOGRAFII
   
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net

[Spis] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [X] [W] [Z]

copy

(PHP 3, PHP 4, PHP 5)

copy -- Kopiuje plik

Opis

bool copy ( string źródło, string przeznaczenie )

Kopiuje plik z źródło do przeznaczenie. Zwraca TRUE w przypadku sukcesu, FALSE w przypadku porażki.

Przykład 1. copy() przykład

<?php
$file
= 'example.txt';
$newfile = 'example.txt.bak'
  
if (!
copy($file, $newfile)) { 
     echo
"kopiowanie pliku $file, nie powiodło się\n"
}
?>

Jeśli chcesz przenieść plik, użyj funkcji rename().

Notatka: W wersji 4.3.0, oba parametry źródło i przeznaczenie mogą być URLami, jeśli został włączony "fopen wrappers". Zobacz fopen() aby uzyskać więcej szczegółów. Jeśli przeznaczenie jest URLem, kopiowanie może się nie powieść w przypadku gdy wrapper nie obsługuje nadpisywania istniejących plików.

Ostrzeżenie

Jeśli docelowy plik istnieje to zostanie nadpisany.

Notatka: Notatka o kompatybilności w Windows: Jeśli kopiujesz plik pusty (o rozmiarze 0 B) copy() zwróci FALSE, lecz plik zostanie poprawnie skopiowany.

Patrz także: move_uploaded_file(), rename() i rozdział dotyczący obsługi przesyłanych (uploadowanych) plików.




User Contributed Notes

bobbfwed at comcast dot net
02-Feb-2006 08:06

I have programmed a really nice program that remotely lets you manage files as if you have direct access to them (http://sourceforge.net/projects/filemanage/). I have a bunch of really handy functions to do just about anything to files or directories.
I know there are others like it, but here is the function I made for this program to copy directories; it will likely need tweaking to work as a standalone script, since it relies of variables set by my program (eg: loc1 -- which dynamically changes in my program):

<?PHP
 
// loc1 is the path on the computer to the base directory that may be moved
define('loc1', 'C:/Program Files/Apache Group/Apache/htdocs', true);

 
// copy a directory and all subdirectories and files (recursive)
  // void dircpy( str 'source directory', str 'destination directory' [, bool 'overwrite existing files'] )
function dircpy($source, $dest, $overwrite = false){

  if(
$handle = opendir(loc1 . $source)){        // if the folder exploration is sucsessful, continue
  
while(false !== ($file = readdir($handle))){ // as long as storing the next file to $file is successful, continue
    
if($file != '.' && $file != '..'){
      
$path = $source . '/' . $file;
       if(
is_file(loc1 . $path)){
         if(!
is_file(loc1 . $dest . '/' . $file) || $overwrite)
           if(!@
copy(loc1 . $path, loc1 . $dest . '/' . $file)){
             echo
'<font color="red">File ('.$path.') could not be copied, likely a permissions problem.</font>';
           }
       } elseif(
is_dir(loc1 . $path)){
         if(!
is_dir(loc1 . $dest . '/' . $file))
          
mkdir(loc1 . $dest . '/' . $file); // make subdirectory before subdirectory is copied
        
dircpy($path, $dest . '/' . $file, $overwrite); //recurse!
      
}
     }
   }
  
closedir($handle);
  }
}
// end of dircpy()
?>

This new function will be in 0.9.7 (the current release of File Manage) which has just been released 2/2/06.
Hope this helps some people.


makarenkoa at ukrpost dot net
26-Jul-2005 01:58

A function that copies contents of source directory to destination directory and sets up file modes.
It may be handy to install the whole site on hosting.
<?php
// copydirr.inc.php
/*
26.07.2005
Author: Anton Makarenko
   makarenkoa at ukrpost dot net
   webmaster at eufimb dot edu dot ua
*/
function copydirr($fromDir,$toDir,$chmod=0757,$verbose=false)
/*
   copies everything from directory $fromDir to directory $toDir
   and sets up files mode $chmod
*/
{
//* Check for some errors
$errors=array();
$messages=array();
if (!
is_writable($toDir))
  
$errors[]='target '.$toDir.' is not writable';
if (!
is_dir($toDir))
  
$errors[]='target '.$toDir.' is not a directory';
if (!
is_dir($fromDir))
  
$errors[]='source '.$fromDir.' is not a directory';
if (!empty(
$errors))
   {
   if (
$verbose)
       foreach(
$errors as $err)
           echo
'<strong>Error</strong>: '.$err.'<br />';
   return
false;
   }
//*/
$exceptions=array('.','..');
//* Processing
$handle=opendir($fromDir);
while (
false!==($item=readdir($handle)))
   if (!
in_array($item,$exceptions))
       {
      
//* cleanup for trailing slashes in directories destinations
      
$from=str_replace('//','/',$fromDir.'/'.$item);
      
$to=str_replace('//','/',$toDir.'/'.$item);
      
//*/
      
if (is_file($from))
           {
           if (@
copy($from,$to))
               {
              
chmod($to,$chmod);
              
touch($to,filemtime($from)); // to track last modified time
              
$messages[]='File copied from '.$from.' to '.$to;
               }
           else
              
$errors[]='cannot copy file from '.$from.' to '.$to;
           }
       if (
is_dir($from))
           {
           if (@
mkdir($to))
               {
              
chmod($to,$chmod);
              
$messages[]='Directory created: '.$to;
               }
           else
              
$errors[]='cannot create directory '.$to;
          
copydirr($from,$to,$chmod,$verbose);
           }
       }
closedir($handle);
//*/
//* Output
if ($verbose)
   {
   foreach(
$errors as $err)
       echo
'<strong>Error</strong>: '.$err.'<br />';
   foreach(
$messages as $msg)
       echo
$msg.'<br />';
   }
//*/
return true;
}
/* sample usage:
WARNING:
if You set wrong $chmod then You'll not be able to access files and directories
in destination directory.
For example: once upon a time I've called the function with parameters:
copydir($fromDir,$toDir,true);
What happened? I've forgotten one parameter (chmod)
What happened next? Those files and directories became inaccessible for me
(they had mode 0001), so I had to ask sysadmin to delete them from root account
Be careful :-)
<?php
require('./copydirr.inc.php');
copydirr('./testSRC','D:/srv/Apache2/htdocs/testDEST',0777,true);
?>
*/
?>


Andrzej Nadziejko (andrzej at vao . pl)
27-Jun-2005 09:52

These functions are to copy and remove big directories:

/*
source files are in source directory
*/
function SetupFolder($dir_name)
{
   mkdir($dir_name,'0777');
   $folder = opendir('source');
   while($file = readdir($folder))
   {   
       if ($file == '.' || $file == '..') {
           continue;
       }
       if(is_dir('source/'.$file))
       {
           mkdir($dir_name.'/'.$file,0777);
           CopyFiles('source/'.$file,$dir_name.'/'.$file);
       }
       else
       {   
           copy('source/'.$file,$dir_name.'/'.$file);
       }
   }
   closedir($folder);
   return 1;
}
//copy many files
function CopyFiles($source,$dest)
{   
   $folder = opendir($source);
   while($file = readdir($folder))
   {
       if ($file == '.' || $file == '..') {
           continue;
       }
      
       if(is_dir($source.'/'.$file))
       {
           mkdir($dest.'/'.$file,0777);
           CopySourceFiles($source.'/'.$file,$dest.'/'.$file);
       }
       else
       {
           copy($source.'/'.$file,$dest.'/'.$file);
       }
      
   }
   closedir($folder);
   return 1;
}
//remove file, directories, subdirectories
function RemoveFiles($source)
{
   $folder = opendir($source);
   while($file = readdir($folder))
   {
       if ($file == '.' || $file == '..') {
           continue;
       }
      
       if(is_dir($source.'/'.$file))
       {
           RemoveFiles($source.'/'.$file);
       }
       else
       {
           unlink($source.'/'.$file);
       }
      
   }
   closedir($folder);
   rmdir($source);
   return 1;
}


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(

 

 
  © 1996-2012 & Reporter.plmiejscao serwisieabonamentwarunki korzystaniaRSSkontakt