0

我有一个在登台站点上运行的脚本,它获取上传的图像,创建一个目录(如果存在)并将图像上传到所述目录。

我正在尝试将创建的目录更改为实时站点并且没有运气。可以肯定的是,这段代码仍在寻找暂存 URL 而不是实时 URL。

function chmodDirectory( $path = '.', $level = 0 ){  
$ignore = array( 'cgi-bin', '.', '..' ); 

$dh = @opendir( $path ); 


while( false !== ( $file = readdir( $dh ) ) ){ // Loop through the directory 
  if( !in_array( $file, $ignore ) ){
    if( is_dir( "$path/$file" ) ){
      chmod("$path/$file",0777);
      chmodDirectory( "$path/$file", ($level+1));
    } else {
      chmod("$path/$file",0777); // desired permission settings
    }//elseif 

  }//if in array 

}//while 

closedir( $dh ); 

}//功能

?> 提前感谢您的帮助!

编辑:问题在于,即使我更改了路径并且数据库存储了正确的 URL,我希望创建或访问的目录仍在暂存目录上创建/访问。

4

2 回答 2

0

PHP 中与文件相关的命令都是“当前工作目录”感知的。您chmodDirectory().路径开头,这意味着“当前工作目录”,默认情况下是脚本所在的目录。

如果您将登台站点作为“实时”站点的子目录运行,则无法将函数按原样指向实时目录,因为您要离开相对的 '.' 目录,只有深入挖掘。例如,如果您的脚本位于:

/home/sites/example.com/htdocs/staging/v1.1/upload.php

那么处理的第一个目录将是

/home/sites/example.com/htdocs/staging/v1.1/

如果要在“实时”区域中启动该过程,则必须使用以下原始路径调用该函数:

chmodDirectory('../..'); // start two directories above the current working dir

或者更好:

chmodDirectory('/home/sites/example.com/htdocs/'); // start at this absolute path

作为路径,因此它将在“实时”版本中工作,而不是在暂存区域内开始。

于 2010-10-05T20:21:54.173 回答
0

嘿伙计们,感谢您的帮助...错误实际上是从 php.ini 设置中的 open_basedir 发生的。我无法编写目录,因为我在子域目录下。

于 2010-10-06T19:59:25.810 回答