我有一个 ubuntu 服务器。我的目标是在根目录中为 ftp 用户(例如,suresh)创建一个目录,将一些文件从后者复制到新创建的目录中。
问题是,我可以创建新目录,但是当我尝试在此目录中复制文件时,它不起作用。
我测试了脚本以在本地(在根目录中)复制文件,它可以工作。我将新创建的目录的权限更改为0777,它可以工作,但不适用于0775。我尝试了两个复制示例。两者都有效。
新创建目录的所有者用户/组是 www-data(它是一个具有 root 访问权限的 ubuntu 服务器)。该目录的权限为 755。将所有者更改为 ftp 用户suresh 也没有成功。
以下是我使用的php:
<?php
//To create directory/subdirectory recursively
$mode = 0775;
mkdir("./directory/subdirectory", $mode, TRUE);
//Source and destination
$source = "index.php";
$dest = "directory/index.php"
//Copy function first version
function stream_copy($src, $dest)
{
$fsrc = fopen($src,'r');
$fdest = fopen($dest,'w+');
$len = stream_copy_to_stream($fsrc,$fdest);
fclose($fsrc);
fclose($fdest);
return $len;
}
if (!stream_copy($source,$dest)){
echo "File stream copy to directory not successful! <br />";
} else {
echo "Check the directory for index file! <br />";
}
//And I always get the "...not successful" output!
//Copy function second version
function copyemz($file1,$file2){
$contentx =@file_get_contents($file1);
$openedfile = fopen($file2, "w");
fwrite($openedfile, $contentx);
fclose($openedfile);
if ($contentx === FALSE) {
$status=false;
} else $status=true;
return $status;
}
if (!copyemz($source,$dest)){
echo "File copy to directory not successful <br />";
} else {
echo "Check the directory for index!<br />";
}
//The same result for this either!
?>
最后我也尝试了 shell_exec 和相同的结果!所有这些都在条件设置下工作
谁能解释我发生了什么或我错过了什么!
ftp (suresh) 的用户是 www-data 的组成员,反之亦然。(如果它有帮助!也尝试过。)