首页 文章

mkdir和php中的递归副本

提问于
浏览
2

我的功能是在创建内容并将其复制到新目录时遇到问题(我也不确定这是否是最好的方法,因此欢迎备用建议) .

我通过 /etc/fstab 安装了2个网络驱动器,如下所示:

//128.251.108.xxx/Data/Agilent_Data /home/lv_admin/uslonsnas001 cifs cred=/etc/.na02passwd,rw,umask=0000,uid=www-data,gid=webgroup 0 0
//128.251.108.xx/c$/Agilent /home/lv_admin/uslonsapp003 cifs cred=/etc/.na02passwd,rw,umask=0000,uid=www-data,gid=webgroup 0 0

基本上,当从 uslonsapp003 mount提示文件路径时,我检查 uslonsnas001 中是否存在目录结构,如果没有则创建递归目录 . 然后我将内容从 uslonsapp003 复制到 uslonsnas001 中的新结构位置 . 这是我的代码:

$pImagePath = "http://uslonsapp003:8080/boardtests/2011/4/29/12/30/8051/Images/E_1-c274.jpg";
//strip off the path name up to '2011' and take off the image name at the end
    $startpos = strpos( $pImagePath, "/boardtests/" ) + strlen( "/boardtests/" );
    $endpos   = strpos( $pImagePath, "/Images/" );
    $file_dir = substr( $pImagePath, $startpos, ( $endpos - $startpos ) );
    $orig_dir = "/home/lv_admin/uslonsapp003/ITFSS/DataStore/BoardTest/" . $file_dir;
    $new_dir  = "/home/lv_admin/uslonsnas001/BoardTest/" . $file_dir;
    if( !is_dir( $new_dir ) )
        if( !shell_exec("mkdir -p $new_dir") )    return array( "status" => 0, "errordesc" => "failed to make dir: '" . $new_dir . "'" );
    if( !shell_exec("cp -r $orig_dir $new_dir") ) return array( "status" => 0, "errordesc" => "failed to copy from: '" . $orig_dir . "' to: '" . $new_dir . "'" );
    return array( "status" => 1 );

我一直在犯这两个错误,'未能成功......'并且'未能复制......'

这是通过Apache执行的,我假设这是一个权限问题,但这只是我的“预感” . 请帮忙!

我已经尝试将 sudo 添加到shell_exec()'s but that still doesn' t工作的开头 .

UPATED1

我发现mkdir失败了,因为当我创建 /home/lv_admin/uslonsnas001 目录时,我没有将其上的mod,所有者和组更改为将使用它的那个(www-data) . 执行以下操作修复了该部分:

$ sudo chmod 775 ~/uslonsnas001
$ sudo chown www-data ~/uslonsnas001
$ sudo chgrp webgroup ~/uslonsnas001

但我仍然遇到复制命令的问题,现在说“模块'ODBC'已经加载”

2 回答

  • 0

    使用 :

    mkdir("path/to/your/directory", 0777, true);
    

    其中0777是chmod和bool true激活递归模式

  • 0

    不幸的是问题很简单 . 我的原始挂载点未设置为root的写入权限 . 将安装点所有者和组更改为root后,它可以正常工作 .

相关问题