Source for file SC_Helper_FileManager.php
Documentation is available at SC_Helper_FileManager.php
* This file is part of EC-CUBE
* Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
* http://www.lockon.co.jp/
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
require_once dirname(__FILE__ ) . '/../../module/Tar.php';
* @author LOCKON CO.,LTD.
* @version $Id: SC_Helper_FileManager.php 20863 2011-04-19 13:52:35Z nanasess $
* @param string $dir 取得するディレクトリパス
while (($file = readdir($dh)) !== false) $arrDir[] = $file;
foreach($arrDir as $file) {
if($file != "." && $file != "..") {
// SELECT内の見た目を整えるため指定文字数で切る
$file_name = SC_Utils_Ex::sfCutString($file, FILE_NAME_LEN);
$file_size = SC_Utils_Ex::sfCutString($this->sfGetDirSize($path), FILE_NAME_LEN);
$arrDirList[$cnt]['file_name'] = $file;
$arrDirList[$cnt]['file_path'] = $path;
$arrDirList[$cnt]['file_size'] = $file_size;
$arrDirList[$cnt]['file_time'] = $file_time;
$arrDirList[$cnt]['is_dir'] = true;
$arrFileList[$cnt]['file_name'] = $file;
$arrFileList[$cnt]['file_path'] = $path;
$arrFileList[$cnt]['file_size'] = $file_size;
$arrFileList[$cnt]['file_time'] = $file_time;
$arrFileList[$cnt]['is_dir'] = false;
* @param string $dir ディレクトリ
if ($file != '..' && $file != '.' && !is_dir($path)) {
} else if (is_dir($path) && $file != '..' && $file != '.') {
// 下層ファイルのバイト数を取得する為、再帰的に呼び出す。
// ディレクトリ(ファイル)が存在しない場合は0byteを返す
if($bytes == "") $bytes = 0;
* @param string $dir 削除するディレクトリ又はファイル
while (false !== ($item = readdir($handle))) {
if ($item != "." && $item != "..") {
$arrResult[$cnt]['result'] = @unlink("$dir/$item");
$arrResult[$cnt]['file_name'] = "$dir/$item";
$arrResult[$cnt]['result'] = @rmdir($dir);
$arrResult[$cnt]['file_name'] = "$dir/$item";
$arrResult[0]['result'] = @unlink("$dir");
$arrResult[0]['file_name'] = "$dir";
* ツリー生成用配列取得(javascriptに渡す用).
* @param string $dir ディレクトリ
* @param string $tree_status 現在のツリーの状態開いているフォルダのパスを
* @return array ツリー生成用の配列
$arrTree[$cnt]['type'] = "_parent";
$arrTree[$cnt]['type'] = "_child";
$arrTree[$cnt]['path'] = $dir;
$arrTree[$cnt]['rank'] = 0;
$arrTree[$cnt]['count'] = $cnt;
if($_POST['mode'] != '') {
$arrTree[$cnt]['open'] = $this->lfIsFileOpen($dir, $tree_status);
$arrTree[$cnt]['open'] = true;
* ツリー生成用配列取得(javascriptに渡す用).
* @param string $dir ディレクトリ
* @param string $default_rank デフォルトの階層
* @param string $tree_status 現在のツリーの状態開いているフォルダのパスが
* @return array ツリー生成用の配列
function sfGetFileTreeSub($dir, $default_rank, &$cnt, &$arrTree, $tree_status) {
while (false !== ($item = readdir($handle))) $arrDir[] = $item;
foreach($arrDir as $item) {
if ($item != "." && $item != "..") {
$arrTree[$cnt]['path'] = $path;
$arrTree[$cnt]['type'] = "_parent";
$arrTree[$cnt]['type'] = "_child";
$arrTree[$cnt]['rank'] = $rank - $default_rank + 1;
$arrTree[$cnt]['count'] = $cnt;
$arrTree[$cnt]['open'] = $this->lfIsFileOpen($path, $tree_status);
* 指定したディレクトリ配下にファイルがあるかチェックする.
* @return bool ファイルが存在する場合 true
if ($file != '..' && $file != '.' && is_dir($path)) {
* 指定したファイルが前回開かれた状態にあったかチェックする.
* @param string $dir ディレクトリ
* @param string $tree_status 現在のツリーの状態開いているフォルダのパスが
* @return bool 前回開かれた状態の場合 true
$arrTreeStatus = explode('|', $tree_status);
* @param string $file ファイルパス
Header("Content-disposition: attachment; filename=". basename($file));
Header("Content-type: application/octet-stream; name=". basename($file));
Header("Cache-Control: ");
* @param string $file ファイルパス
* @param integer $mode パーミッション
* @return bool ファイル作成に成功した場合 true
$ret = @mkdir($file, $mode);
$fp = @fopen($filename, 'rb' );
* @param string $filename ファイルパス
* @param string $value 書き込み内容
* @return boolean ファイルの書き込みに成功した場合 true
SC_Utils_Ex::recursiveMkdir(dirname($filename), 0777);
$fp = fopen($filename,'w');
if (fwrite($fp, $value) === false) {
* ユーザが作成したファイルをアーカイブしダウンロードさせる
* @param string $dir アーカイブを行なうディレクトリ
* @param string $template_code テンプレートコード
* @return boolean 成功した場合 true; 失敗した場合 false
$dlFileName = 'tpl_package_' . $template_code . '_' . date('YmdHis') . '.tar.gz';
$debug_message = $dir . " から " . $dlFileName . " を作成します...\n";
$arrFileHash = SC_Utils_Ex::sfGetFileList($dir);
foreach($arrFileHash as $val) {
$arrFileList[] = $val['file_name'];
$debug_message.= "圧縮:". $val['file_name']. "\n";
GC_Utils_Ex::gfPrintLog($debug_message);
$tar = new Archive_Tar($dlFileName, true);
if ($tar->create($arrFileList)) {
header("Content-disposition: attachment; filename=${dlFileName}");
header("Content-type: application/octet-stream; name=${dlFileName}");
unlink($dir . "/" . $dlFileName);
* @param string $path アーカイブパス
* @return boolean Archive_Tar::extractModify()のエラー
$tar = new Archive_Tar($path, true);
$unpacking_name = preg_replace("/(\.tar|\.tar\.gz)$/", "", $file_name);
$result = $tar->extractModify($dir. "/", $unpacking_name);
GC_Utils_Ex::gfPrintLog("解凍:" . $dir. "/". $file_name. "->". $dir. "/". $unpacking_name);
SC_Utils_Ex::sfDelFile($dir . "/" . $unpacking_name);
Documentation generated on Fri, 24 Feb 2012 14:02:43 +0900 by Seasoft
|