Ejemplo n.º 1
0
 public function executeImportarList(sfWebRequest $request)
 {
     // Preparo el id y name del proyecto para la proxima accion
     $this->proyecto = array();
     $this->proyecto['id'] = $request->getPostParameter('proyecto[id]');
     $this->proyecto['name'] = $request->getPostParameter('proyecto[name]');
     $files = $_FILES;
     // Controles antes de subir el archivo:
     // - Que tenga contenido
     // - Que sea permitido
     // - Que sea valido
     $this->error = array();
     if ($files['filews']['size'] == 0) {
         $this->error[] = "ERROR: Zero byte file upload";
     }
     $allowedFileTypes = array("application/zip");
     if (!in_array($files['filews']['type'], $allowedFileTypes)) {
         $this->error[] = "ERROR: File type not permitted";
     }
     if (!is_uploaded_file($files['filews']['tmp_name'])) {
         $this->error[] = "ERROR: Not a valid file upload";
     }
     if (count($this->error) > 0) {
         return sfView::ERROR;
     }
     // Bien, sigo adelante
     // Defino directorio sobre el cual trabajar
     $temp_dir = tempnam(sys_get_temp_dir(), 'ws') . 'd';
     mkdir($temp_dir);
     // Descomprimo el archivo
     $zip = new Zipper();
     if ($zip->open($files['filews']['tmp_name']) === TRUE) {
         if ($zip->extractTo($temp_dir) === TRUE) {
             // Recupero en un array la lista de documentos xpdl
             $finder = sfFinder::type('file')->name('*.xpdl');
             $this->proyecto['files'] = $finder->in($temp_dir);
             return sfView::SUCCESS;
         }
     }
     // Si llego aca es porque hubo problemas al descomprimir o tratar el zip
     return sfView::ERROR;
 }
Ejemplo n.º 2
0
                 }
                 closedir($dr);
                 foreach ($nodes as $node) {
                     $nnode = iconv("GBK", "UTF-8", $node);
                     echo $nnode . '<br>';
                     if (is_dir($node)) {
                         $this->addDir2($node);
                     } elseif (is_file($node)) {
                         $this->addFile($node);
                     }
                 }
             }
         }
         $zip = new Zipper();
         $time = date('D-d-M-g-h-s', $_SERVER['REQUEST_TIME']);
         $res = $zip->open($_SESSION['folder'] . 'Backup-' . $time . '.zip', ZipArchive::CREATE);
         if ($res === TRUE) {
             $f = substr($_SESSION['folder'], 0, -1);
             $zip->addDir($f);
             $zip->close();
             echo "压缩完成,文件保存为Backup-" . $time . ".zip<br>你可以 <a href=\"" . $meurl . "?op=home&folder=" . $_SESSION['folder'] . "\">查看文件夹</a> 或者 <a href=\"" . $meurl . "?op=home\">返回上次浏览的文件夹</a></div>\n";
         } else {
             echo '<span class="error">压缩失败!</span>' . "</div>\n";
         }
         mainbottom();
     } else {
         printerror('此服务器上的PHP不支持ZipArchive,无法压缩文件!');
     }
 } else {
     printerror("您没有选择文件");
 }
Ejemplo n.º 3
0
        foreach ($nodes as $node) {
            //print $node . '<br>';
            if (is_dir($node)) {
                if (!$onlystatus) {
                    $this->addDir($node);
                }
            } else {
                if (is_file($node)) {
                    $this->addFile($node);
                }
            }
        }
    }
}
/********************************************************************************/
include_once "../includes/main_back_inc.php";
$zip = new Zipper();
$ourFileName = "testFile.zip";
if ($zip->open($ourFileName, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)) {
    $zip->addDir('../upload/products');
    $zip->addDir('../upload', true);
    $zip->close();
} else {
    alert('匯出檔案資料失敗!!', '/');
    exit;
}
$filename = date("YmdHis");
header("Content-type: application/zip, application/octet-stream");
header("Content-Disposition: attachment; filename={$filename}.zip");
readfile($ourFileName);
unlink($ourFileName);
Ejemplo n.º 4
0
 /**
  * Comprime un archivo o directorio
  * Uso: UtilPsdf::comprimir('/home/usuario/foo/', '/home/usuario/foo.zip')
  * NOTA: Si se comprimirá un directorio este debe finalizar con la barra.
  * @param string $ruta Ruta del archivo/directorio a comprimir
  * @param string $zip_salida Ruta/nombre del zip a generar
  * @return boolean
  */
 public static function comprimir($ruta, $zip_salida)
 {
     $zip = new Zipper();
     if ($zip->open($zip_salida, ZIPARCHIVE::CREATE) === TRUE) {
         $zip->addFolder($ruta);
         $zip->close();
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 5
0
$name = $_REQUEST["n"];
$dirPath = $_REQUEST["d"];
$date = new DateTime();
$archName = "backup/" . $name . "_" . $date->format("YmdHis") . ".zip";
class Zipper extends ZipArchive
{
    public function addDir($path)
    {
        $this->addEmptyDir($path);
        $nodes = glob($path . '/*');
        foreach ($nodes as $node) {
            if (is_dir($node)) {
                $this->addDir($node);
            } else {
                if (is_file($node)) {
                    $this->addFile($node);
                }
            }
        }
    }
}
$zip = new Zipper();
if ($zip->open($archName, ZipArchive::CREATE)) {
    //=== TRUE) {
    $zip->addDir($dirPath);
    $zip->close();
    echo "{\"archive\":\"{$archName}\"}";
} else {
    echo "{\"error\":\"Backup error. Can't open file '{$archName}'\"}";
}
Ejemplo n.º 6
0
 public function exportProject($exportsettings, $dontsavesettings = false)
 {
     $userid = $this->getUserId();
     $projectid = $this->getProjectId();
     $data = $this->loadProjectData();
     if (!$dontsavesettings) {
         $this->userdata->saveExportSettings($exportsettings);
     }
     //		$theme = (strlen($exportsettings['styleTemplate'])) ? $exportsettings['styleTemplate'] : 'default';
     $theme = "default";
     $zip = new Zipper();
     $filename = $this->projectpath . $data['path'] . "/" . $this->standardize($data['project']) . '.zip';
     if (@file_exists($filename)) {
         @unlink($filename);
     }
     if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
         exit("cannot open <{$filename}>\n");
     }
     $zip->addEmptyDir('images');
     $zip->addEmptyDir('thumbs');
     $zip->addEmptyDir('audio');
     $zip->addEmptyDir('config');
     $zip->addDir('./css');
     $zip->addFile('./themes/' . $theme . '/css/styles.css', './css/styles.css');
     $zip->addEmptyDir('icons');
     $zip->addFilesFromDir('./themes/' . $theme . '/icons', './icons');
     $zip->addDir('./js');
     $zip->addFile('_index.html', '/index.html');
     $zip->addFile('integration.html', '/integration.html');
     $zip->addFile('_index_computer.html', '/_index_computer.html');
     $zip->addFile('./flash/mmslides.swf', '/mmslides.swf');
     $imageformat = strlen($exportsettings['width']) ? $exportsettings['width'] : "1024";
     foreach ($data['data']['slides'] as $idx => $filedata) {
         if (array_key_exists('file', $filedata) && strlen($filedata['file'])) {
             $filepaths = array('1280' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "1280" . DIRECTORY_SEPARATOR . $filedata['file'], '1024' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "1024" . DIRECTORY_SEPARATOR . $filedata['file'], '800' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "800" . DIRECTORY_SEPARATOR . $filedata['file'], '640' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "640" . DIRECTORY_SEPARATOR . $filedata['file'], '480' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "480" . DIRECTORY_SEPARATOR . $filedata['file'], '320' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "320" . DIRECTORY_SEPARATOR . $filedata['file']);
             foreach ($filepaths as $filesize => $filepath) {
                 if (@file_exists($filepath)) {
                     $zip->addFile($filepath, '/images/' . $filesize . '/' . $filedata['file']);
                 }
                 $thumbpath = $this->projectpath . $data['path'] . "/thumbs/" . $filedata['file'];
                 if (@file_exists($thumbpath)) {
                     $zip->addFile($thumbpath, '/thumbs/' . $filedata['file'] . ".thumb.jpg");
                 }
             }
         }
     }
     $audiotrack = $data['data']['meta']['audio'];
     if (is_array($audiotrack) && strlen($audiotrack['file']) > 0) {
         $audiopath = $this->projectpath . $data['path'] . "/" . $audiotrack['file'];
         if (@file_exists($audiopath)) {
             $zip->addFile($audiopath, '/audio/' . $audiotrack['file']);
         }
     }
     $projectdata = $data;
     if (strlen($exportsettings['password'])) {
         $exportsettings['password'] = md5($exportsettings['password']);
     }
     $projectdata['slideshow'] = $exportsettings;
     $zip->addFromString('config/jsonconfig.js', json_encode($projectdata));
     $zip->close();
     return array('url' => $data['path'] . '/' . basename($filename));
 }