在php中将文件从一个文件复制到另一个文件无效

时间:2017-11-21 11:27:28

标签: php copy

尝试在copy中将PHP个文件从一个目录移到另一个目录,但不是在复制。

我的代码:

<?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>";
?>

2 个答案:

答案 0 :(得分:0)

错误应该在这里:

1:尝试检查 string[] xs = parseString.Split(new string[] { "xpath::", "{", "}" }, StringSplitOptions.RemoveEmptyEntries); XPathNavigator nav = ((XmlDocument)args[0]).CreateNavigator(); try { var xn = nav.Evaluate(xs[0]); switch (xn.GetType().Name) { case "String": return (string)xn; case "XPathSelectionIterator": return nav.SelectSingleNode(xs[0]).Value; case "Double": return xn.ToString(); case "Boolean": return xn.ToString().ToLower(); } } catch (Exception ex) { this.log(new XPathException(ex.Message)); this.log(new XPathException(string.Format("No data for xpath ->{0}", parseString))); if (parseString.Contains("N104") || parseString.Contains("N401") || parseString.Contains("N402")) return " "; if (parseString.Contains("N403")) return " "; return " "; } return parseString; } (如何使用权限?请参阅http://php.net/manual/en/function.chmod.php

2:FOLDER PERMISSION不存在(您正在使用Parent folder)。

Copy()的工作原理:

../

将文件 bool copy ( string $source , string $dest [, resource $context ] ) 的副本复制到source

  

如果目标文件已存在,则会被覆盖。

如何设置权限(Linux)? :

如果您使用的是VPS / Dedicated,请转到Linux终端并使用命令dest。如果您使用共享主机,只需转到sudo chmod 755 -R folder_name文件夹并使用www

按照给定步骤设置权限

答案 1 :(得分:-1)

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/