Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:将文件复制到Ubuntu中PHP创建的目录';行不通_Php_File_Ubuntu_Directory_Copy - Fatal编程技术网

PHP:将文件复制到Ubuntu中PHP创建的目录';行不通

PHP:将文件复制到Ubuntu中PHP创建的目录';行不通,php,file,ubuntu,directory,copy,Php,File,Ubuntu,Directory,Copy,我有一个ubuntu服务器。我的目标是在根目录中为ftp用户(比如说suresh)创建一个目录,将一些文件从后者复制到新创建的目录中 问题是,我可以创建新目录,但当我尝试复制此目录中的文件时,它将不起作用。 我测试了脚本以在本地复制文件(在根目录中),它可以工作。我将新创建的目录的权限更改为0777,它可以工作,但不适用于0775。我试过两个复制的例子。两者都有效 新创建的目录的所有者用户/组是www数据(它是一个具有根访问权限的ubuntu服务器)。该目录的权限为755。将所有者更改为ftp用

我有一个ubuntu服务器。我的目标是在根目录中为ftp用户(比如说suresh)创建一个目录,将一些文件从后者复制到新创建的目录中

问题是,我可以创建新目录,但当我尝试复制此目录中的文件时,它将不起作用。

我测试了脚本以在本地复制文件(在根目录中),它可以工作。我将新创建的目录的权限更改为0777,它可以工作,但不适用于0775。我试过两个复制的例子。两者都有效

新创建的目录的所有者用户/组是www数据(它是一个具有根访问权限的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数据的组成员,反之亦然。(如果有用的话!也尝试了其他方法。)

创建“/directory/subdirectory”,但复制到“directory/”。那么,您确定“direcotry”也归www数据所有吗?

是的。“目录”归www数据用户和组所有。此外,当前目录中的“./目录”和“目录”的含义相同。所以,没关系。现在有什么建议吗?