问题
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>";
?>
回答1:
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
回答2:
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/
来源:https://stackoverflow.com/questions/47411981/copy-files-from-one-to-another-in-php-not-working