Esempio n. 1
0
 public function actionZip()
 {
     Yii::import('application.helpers.vendors.zip.clsTbsZip');
     $zip = new clsTbsZip();
     /**create**/
     //		$zip->CreateNew();
     //
     //		$zip->FileAdd('sub/test2.txt', './public/test2.txt',TBSZIP_FILE);
     //
     //		$zip->Flush(TBSZIP_FILE, './public/zip/test.zip');
     $zipfile = './public/zip/test.zip';
     $tmpfile = './public/zip/tmp.zip';
     $zip->Open($zipfile);
     //		echo $zip->FileExists('test2.txt');
     if (!$zip->FileExists('test.txt')) {
         $zip->FileAdd('test.txt', './public/test.txt', TBSZIP_FILE);
     }
     if (!$zip->FileExists('pclzip-2-8.zip')) {
         $zip->FileAdd('pclzip-2-8.zip', './public/zip/pclzip-2-8.zip', TBSZIP_FILE);
     }
     //		$zip->FileAdd('hello.jpg', './public/uploadfiles/82671333902992.jpg', TBSZIP_FILE);
     echo $zip->FileRead('pclzip-2-8.zip');
     //		$zip->Flush(TBSZIP_DOWNLOAD, 'download.zip');
     //		echo $zip->FileRead('test.txt');
     //		foreach ($zip->CdFileLst as $file)
     //		{
     //			UtilHelper::dump($zip->FileRead($file['v_name']));
     //		}
     $zip->Flush(TBSZIP_FILE, $tmpfile);
     //		$zip->Flush(TBSZIP_DOWNLOAD, 'download.zip', 'application/zip');
     $zip->close();
     //		if (file_exists($zipfile)){
     //			unlink($zipfile);
     //
     //			copy($tmpfile, $zipfile);
     //
     //			unlink($tmpfile);
     //		}
 }
Esempio n. 2
0
 function handleOOXMLUpload()
 {
     if (isset($_FILES['uploaded'])) {
         $target = './upload/pptx/' . $_SESSION['uid'] . '/';
         if (!file_exists($target)) {
             mkdir($target);
         }
         $target = $target . basename($_FILES['uploaded']['name']);
         $pptxType = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
         if ($_FILES['uploaded']['type'] != $pptxType) {
             $message = '<div id="error-type">File type not supported! Please, upload .pptx files.</div>';
             // die();
         } elseif ($_FILES['uploaded']['error'] === UPLOAD_ERR_OK) {
             if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
                 if (isset($_POST['import_with_style'])) {
                     $import_with_style = $_POST['import_with_style'];
                 } else {
                     $import_with_style = false;
                 }
                 // quick fix for cheking file formatting
                 $zip = new clsTbsZip();
                 $zip->Open($target);
                 if ($zip->FileExists('docProps/core.xml')) {
                     $proper_pptx = true;
                 } else {
                     $proper_pptx = false;
                 }
                 $zip->Close();
                 if ($proper_pptx) {
                     $pr = new pptxPresentation($target, $import_with_style);
                     $deck_num = $pr->saveToDB($this->_user['id']);
                 } else {
                     $message = '<div id="error-type">Not proper .pptx format! Open Office .pptx files are not supported yet.</div>';
                 }
             } else {
                 $message = 'Sorry, there was a problem uploading your file.';
             }
         } else {
             $message = $this->file_upload_error_message($_FILES['uploaded']['error']);
         }
     } else {
         $message = '<div id="error-type">There was no file to upload.</div>';
     }
     if (empty($message)) {
         $this->set('deck_num', $deck_num);
     } else {
         $this->set('message', $message);
     }
 }
if (file_exists('tbszip.php')) {
    include_once 'tbszip.php';
} else {
    include_once '../tbs_plugin_opentbs.php';
}
$file_lst = array('demo_oo_text.odt', 'demo_oo_formula.odf', 'demo_oo_graph.odg', 'demo_oo_presentation.odp', 'demo_oo_spreadsheet.ods');
$version = '1.2';
// valeur par défaut à mettre dans le manifest
$manifest = 'META-INF/manifest.xml';
$styles = 'styles.xml';
$odf = new clsTbsZip();
foreach ($file_lst as $file) {
    $odf->Open($file);
    echo "<h4>Étude du fichier '{$file}'.</h4>\r\n";
    $extension = strtolower(substr($file, -4));
    if (!$odf->FileExists($manifest)) {
        echo "Le fichier manifest n'a pas été trouvé.<br>\r\n";
        continue;
    }
    /* debug
    	if (file_exists('manifest.xml')) {
    		$odf->FileReplace($manifest, 'manifest.xml', TBSZIP_FILE);
    		$temp = $file.'.tmp.odt';
    		$odf->Flush(TBSZIP_FILE, $temp);
    		echo "Fichier fanifest remplacé par le fichier 'manifest.xml' trouvé dans le répertoire.<br>\r\n";
    		exit;
    	}
    	*/
    $txt = $odf->FileRead($manifest);
    // des fois la version figure dans un élément <manifest:file-entry>, lé cas échéant, on va chercher la bonne version du manifeste.
    $att = ' manifest:version="';
Skrol29, 2010-09-03
*/
include_once 'tbszip.php';
// load the TbsZip library
$zip = new clsTbsZip();
// create a new instance of the TbsZip class
$zip->CreateNew();
// start a new empty archive for adding files
// or
$zip->Open('an_existing_archive.zip');
// open an existing archive for reading and/or modifying
// --------------------------------------------------
// Reading information and data in the opened archive
// --------------------------------------------------
// check if a file is existing in the archive, the name must precise subfolders if any
$ok = $zip->FileExists('subfolder/help.html');
// count the files stored in the archive
$file_nbr = count($zip->CdFileLst);
// retrieve the content of an compressed file in the archive
$text1 = $zip->FileRead('readme.txt');
// retrieve the content of an compressed file in a subfolder of the archive
$text2 = $zip->FileRead('subfolder/readme.txt');
if ($ok) {
    $zip->FileExists('subfolder/help.html');
}
// -----------------------------
// Modifying data in the archive
// -----------------------------
// add a file in the archive
$zip->FileAdd('newfile.txt', $data, TBSZIP_STRING);
// add the file by giving the content