SoFunction
Updated on 2025-03-09

How to copy files without using copy function

This article example describes the method of php copying files without using the copy() function. Share it for your reference. The details are as follows:

The following code does not use the built-in copy function in PHP, and directly copy the file through the operation method of reading and writing of the file.

<?php 
function copyfiles($file1,$file2){ 
 $contentx =@file_get_contents($file1); 
  $openedfile = fopen($file2, "w"); 
  fwrite($openedfile, $contentx); 
  fclose($openedfile); 
   if ($contentx === FALSE) { 
   $status=false; 
   }else $status=true; 
   return $status; 
  } 
?>

I hope this article will be helpful to everyone's PHP programming.