2013-10-14 61 views
0

我正在处理将所有zpanel备份上传到我的Amazon S3帐户的脚本。如果我不使用zpanel备份,并使用CronJob创建和上传由我创建的备份,它就可以工作。移动Zpanel默认备份目录或Opendir备份目录

我无法上传zpanel备份的原因是我找不到使用php opendir函数访问“备份”目录的方法。

我知道备份文件夹的绝对路径。并且当它看来,这绝对路径不会opendir()

工作,我用:opendir('var/zpanel/hostdata/my_username/backups/')

而且它不会工作。现在,如果我想使用相对路径,我也无法到达那里。

那么,有没有一种方法可以将zPanel Backups目录移动到public_html文件夹内的某处?或者,可以访问备份文件夹的网址? Ajaxplorer可以到达那里,为什么我不能?

如果没有可能的话,我会非常感谢,如果有人能教我创建像zPanel一样的备份(所有DB + public_html文件夹中的所有内容)。

的代码看起来像这样

require_once('S3.php'); 

// Enter your amazon s3 creadentials 
$s3 = new S3('xxxxx', 'xxxxx'); 

if ($handle = opendir('var/zpanel/hostdata/my_username/backups/')) { 
    while (false !== ($file = readdir($handle))) { 
     if ($file != "." && $file != "..") { 
      //echo "okay"; 
      echo $file; exit; 

      if ($s3->putObjectFile("backups/$file", "my_basket", "$file", S3::ACL_PUBLIC_READ)) { 
        echo "<strong>We successfully uploaded your file.<br /></strong>"; 
        //this will delete the file from your server after upload 
        //if (file_exists($baseurl . '/' . $file)) { unlink ($baseurl . '/' . $file); } 
      }else{ 
       echo "<strong>Something went wrong while uploading your file... sorry.</strong>"; 
      } 

     }else{ 
      echo "No file found here ".$root; 
     } 
    } 
    closedir($handle); 
} 

非常感谢提前!

回答

0

您的代码中存在拼写错误。如果要使用绝对路径opendir,请确保它以斜杠开头(/)。所以,正确的版本是:

opendir('/var/zpanel/hostdata/my_username/backups/') 

如果仍然不能得到这个工作,请确认您传递给opendir路径的确是一个目录,也验证权限在该目录,以确保您的PHP进程可以从中读取。

PHP doc

如果路径不是有效目录或目录无法打开 因为权限限制或文件系统错误,执行opendir()返回FALSE ...

另外,如果您在php.ini或代码中使用任何open-basedir restrictions,请确保您传递给opendir的路径不受这些限制的阻止。