PHP:在Ubuntu中将文件复制到PHP -created-directory目录不起作用


PHP: Copy file to php-created-directory in Ubuntu didn't work

我有一个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的组成员,反之亦然。(如果有帮助的话!

您创建"。/directory/subdirectory",但你复制到"directory/"。那么你确定"目录"也属于www-data吗?