Copy files from one to another in php not working

…衆ロ難τιáo~ 提交于 2021-02-20 00:46:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!