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挂载的文件路径时,我会检查目录结构是否存在,uslonsnas001如果不存在则创建递归目录。然后我将内容uslonsapp003uslonsnas001. 这是我的代码:

$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() 的开头,但这仍然不起作用。

已更新1

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

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

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

4

2 回答 2

0

采用 :

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

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

于 2011-06-23T12:42:35.367 回答
0

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

于 2011-08-17T19:52:37.083 回答