简体   繁体   中英

Copy files from one to another in php not working

Trying to copy files from one directory to another in PHP , but it is not copying.

My Code:

<?php
copy('lang.php', '../lang.php');  //lang.php
copy('db_doc.php', '../me/db.php'); //db.php
copy('vdb_doc.php', '../me/vdb.php'); //db.php
copy('db_log.php', '../dbconfig.php'); //dbconfig.php
copy('inser_sql.php', '../inser_sql.php'); //inser_sql.php

echo "Installation Successful! <a href='../'>Go Back</a>";
?>

Error should be here :

1: Try to check FOLDER PERMISSION (How to play with Permission ? see http://php.net/manual/en/function.chmod.php )

2: Parent folder does not exist (you are using ../ ).

How Copy() works :

 bool copy ( string $source , string $dest [, resource $context ] )

Makes a copy of the file source to dest .

If the destination file already exists, it will be overwritten.

How to set Permission (Linux) ? :

Go to your Linux Terminal and use command sudo chmod 755 -R folder_name , if you are using VPS/Dedicated. if you are using Shared Hosting simply go to www folder and set permission by following given steps using UI

1. Folder permission - so try to give that folder recursive permission.
2. Use 
bool copy ( string $source , string $dest [, resource $context ]) function
eg: $file = '/test1/example.txt'; 
$newfile = '/test2/example.txt';
if(!copy($file,$newfile)){
  echo "failed to copy $file";
}else{
  echo "copied $file into $newfile\n";
}

Refer this link as well - 
http://www.phpkida.com/php-tutorial/copy-multiple-files-from-one-folder-to-another-php/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM