简体   繁体   English

能够删除文件,无法复制或修改它们-PHP

[英]Able to delete files, Unable to copy or modify them - PHP

Using the following code I receive an error when trying to copy a file, or anything else I try to do with it. 使用以下代码,当我尝试复制文件或其他与之相关的操作时收到错误消息。 I am however able to use almost identical code to delete the file. 但是,我可以使用几乎相同的代码删除文件。

$file = "img1.jpg";

if (!copy($file, "img2.jpg")) {
  echo ("Error copying $file");
} else {
  echo ("Copied $file");
}

Delete Code: 删除代码:

if (!unlink($file)) {
  echo ("Error deleting $file");
} else {
  echo ("Deleted $file");
}

Anyone know why it might be doing this? 有人知道为什么会这样做吗?

Edit: Apache owns the files but seems to be unable to read or write them as per is_readable and is_writeable 编辑:Apache拥有文件,但似乎无法按照is_read和is_writeable读取或写入它们

Edit2: added second argument to the copy code. Edit2:在复制代码中添加了第二个参数。 This was not the problem, just me making errors in posting this question. 这不是问题,只是我在发布此问题时出错。

$file = "img1.jpg";
$newFile = "img1_copy.jpg";

if (!copy($file, $newFile)) {
  echo ("Error copying $file");
} else {
  echo ("Copied $file");
}

http://php.net/manual/en/function.copy.php http://php.net/manual/zh/function.copy.php

The function copy() requires 2 arguments. 函数copy()需要2个参数。

Change all permissions manually for each file, so that www-data owns it, and www-data (the group) can read and write to it. 手动更改每个文件的所有权限,以便www-data拥有它,并且www-data(该组)可以对其进行读写。 Apache did something weird and while the apache user owned and could read and write to the file, the group www-data was unable to do either. Apache做了一些奇怪的事情,虽然apache用户拥有并可以读写文件,但是www-data组却无法执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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