當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ZipArchive::addFromString方法代碼示例

本文整理匯總了PHP中ZipArchive::addFromString方法的典型用法代碼示例。如果您正苦於以下問題:PHP ZipArchive::addFromString方法的具體用法?PHP ZipArchive::addFromString怎麽用?PHP ZipArchive::addFromString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ZipArchive的用法示例。


在下文中一共展示了ZipArchive::addFromString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: zipData

function zipData($source, $destination)
{
    if (extension_loaded('zip')) {
        if (file_exists($source)) {
            $zip = new ZipArchive();
            if ($zip->open($destination, ZIPARCHIVE::CREATE)) {
                $source = realpath($source);
                if (is_dir($source)) {
                    $iterator = new RecursiveDirectoryIterator($source);
                    // skip dot files while iterating
                    $iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
                    $files = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
                    foreach ($files as $file) {
                        $file = realpath($file);
                        if (is_dir($file)) {
                            $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
                        } else {
                            if (is_file($file)) {
                                $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
                            }
                        }
                    }
                } else {
                    if (is_file($source)) {
                        $zip->addFromString(basename($source), file_get_contents($source));
                    }
                }
            }
            echo $destination . ' zip: successfully...';
            echo "\n";
            return $zip->close();
        }
    }
    return false;
}
開發者ID:phn007,項目名稱:BuildHtml,代碼行數:35,代碼來源:zip.php

示例2: create

 /**
  * @inheritDoc
  */
 public static function create(Request $request, $directory)
 {
     $order = $request->getOrder();
     // Create the filename based on the order name.
     $zipFilePath = sprintf('%s/%s.zip', rtrim(rtrim($directory), '/'), $order->getOrderName());
     // Create a new ZipFile on disk.
     $zip = new \ZipArchive();
     $zip->open($zipFilePath, \ZipArchive::CREATE);
     // Add the order to the archive as an xml file.
     $encoder = new XmlEncoder();
     $zip->addFromString('order.xml', $encoder->encode($order));
     // Add the files to the archive.
     foreach ($request->getFiles() as $fileName => $filePath) {
         $zip->addFile($filePath, 'Input/' . $fileName);
     }
     // Add the content to the archive.
     foreach ($request->getContent() as $fileName => $content) {
         $zip->addFromString('Input/' . $fileName, $content);
     }
     // Close the file so the content gets compressed and the file is saved.
     $result = $zip->close();
     // Check if no errors.
     if ($result !== true || !file_exists($zipFilePath)) {
         throw new FileException(sprintf('Can\'t create the zip archive "%s"', $zipFilePath));
     }
     return new static($zipFilePath);
 }
開發者ID:MPParsley,項目名稱:xconnect,代碼行數:30,代碼來源:ZipFile.php

示例3: zip

 public static function zip($source)
 {
     if (!extension_loaded('zip') || !file_exists($source)) {
         return false;
     }
     $zippedfile = uniqid(sys_get_temp_dir() . "/") . ".zip";
     $zip = new ZipArchive();
     if (!$zip->open($zippedfile, ZIPARCHIVE::CREATE)) {
         return false;
     }
     if (is_dir($source) === true) {
         $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
         foreach ($files as $file) {
             // Ignore "." and ".." folders
             if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..'))) {
                 continue;
             }
             if (is_dir($file) === true) {
                 $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
             } else {
                 if (is_file($file) === true) {
                     $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
                 }
             }
         }
     } else {
         if (is_file($source) === true) {
             $zip->addFromString(basename($source), file_get_contents($source));
         }
     }
     $zip->close();
     return $zippedfile;
 }
開發者ID:alerque,項目名稱:bibledit,代碼行數:33,代碼來源:archive.php

示例4: Zip

 public function Zip($source, $destination, $overwrite = false)
 {
     if (!extension_loaded('zip') || !file_exists($source)) {
         return false;
     }
     $zip = new ZipArchive();
     if (!$zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE)) {
         return false;
     }
     $source = str_replace('\\', '/', realpath($source));
     if (is_dir($source) === true) {
         $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
         foreach ($files as $file) {
             $file = str_replace('\\', '/', $file);
             // Ignore "." and ".." folders
             if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..'))) {
                 continue;
             }
             $file = realpath($file);
             if (is_dir($file) === true) {
                 $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
             } else {
                 if (is_file($file) === true) {
                     $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
                 }
             }
         }
     } else {
         if (is_file($source) === true) {
             $zip->addFromString(basename($source), file_get_contents($source));
         }
     }
     return $zip->close();
 }
開發者ID:googlesky,項目名稱:snsp.vn,代碼行數:34,代碼來源:process.class.php

示例5: Zip

function Zip($source, $destination)
{
    // Função que cira o arquivo zip a partir do diretorio informado
    $zip = new ZipArchive();
    if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
        return false;
    }
    $source = str_replace('\\', '/', realpath($source));
    if (is_dir($source) === true) {
        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
        foreach ($files as $file) {
            $file = str_replace('\\', '/', $file);
            // Ignore "." and ".." folders
            if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..'))) {
                continue;
            }
            $file = realpath($file);
            if (is_dir($file) === true) {
                $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
            } else {
                if (is_file($file) === true) {
                    $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
                }
            }
        }
    } else {
        if (is_file($source) === true) {
            $zip->addFromString(basename($source), file_get_contents($source));
        }
    }
    return $zip->close();
}
開發者ID:mithilpatel07,項目名稱:cacic,代碼行數:32,代碼來源:extrator.php

示例6: save

 /**
  * Save PHPExcel to file
  *
  * @param 	string 		$pFileName
  * @throws 	Exception
  */
 public function save($pFilename = null)
 {
     if (!is_null($this->_spreadSheet)) {
         // Garbage collect...
         foreach ($this->_spreadSheet->getAllSheets() as $sheet) {
             $sheet->garbageCollect();
         }
         // Create new ZIP file and open it for writing
         $objZip = new ZipArchive();
         // Try opening the ZIP file
         if ($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !== true) {
             if ($objZip->open($pFilename, ZIPARCHIVE::CREATE) !== true) {
                 throw new Exception("Could not open " . $pFilename . " for writing.");
             }
         }
         // Add media
         for ($i = 0; $i < $this->_spreadSheet->getSheetCount(); $i++) {
             for ($j = 0; $j < $this->_spreadSheet->getSheet($i)->getDrawingCollection()->count(); $j++) {
                 if ($this->_spreadSheet->getSheet($i)->getDrawingCollection()->offsetGet($j) instanceof PHPExcel_Worksheet_BaseDrawing) {
                     $imgTemp = $this->_spreadSheet->getSheet($i)->getDrawingCollection()->offsetGet($j);
                     $objZip->addFromString('media/' . $imgTemp->getFilename(), file_get_contents($imgTemp->getPath()));
                 }
             }
         }
         // Add phpexcel.xml to the document, which represents a PHP serialized PHPExcel object
         $objZip->addFromString('phpexcel.xml', $this->_writeSerialized($this->_spreadSheet, $pFilename));
         // Close file
         if ($objZip->close() === false) {
             throw new Exception("Could not close zip file {$pFilename}.");
         }
     } else {
         throw new Exception("PHPExcel object unassigned.");
     }
 }
開發者ID:abhinay100,項目名稱:fengoffice_app,代碼行數:40,代碼來源:Serialized.php

示例7: zip

 public static function zip($source, $destination)
 {
     ini_set('max_execution_time', 600);
     ini_set('memory_limit', '1024M');
     if (file_exists($source)) {
         $zip = new ZipArchive();
         if ($zip->open($destination, ZIPARCHIVE::CREATE)) {
             $source = realpath($source);
             if (is_dir($source)) {
                 $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
                 foreach ($files as $file) {
                     $file = realpath($file);
                     if (is_dir($file)) {
                         $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
                     } else {
                         if (is_file($file)) {
                             $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
                         }
                     }
                 }
             } else {
                 if (is_file($source)) {
                     $zip->addFromString(basename($source), file_get_contents($source));
                 }
             }
         } else {
             throw new Exception("Could'nt open Destination ZIP File: {$destination}");
         }
         return $zip->close();
     } else {
         throw new Exception("source does not exists");
     }
     return false;
 }
開發者ID:xerox8521,項目名稱:FS-Gamepanel,代碼行數:34,代碼來源:Utils.class.php

示例8: downloadAction

 public function downloadAction()
 {
     $squadID = $this->params('id', 0);
     $squadRepo = $this->getEntityManager()->getRepository('Frontend\\Squads\\Entity\\Squad');
     /** @var Squad $squadEntity */
     $squadEntity = $squadRepo->findOneBy(array('user' => $this->identity(), 'id' => $squadID));
     if (!$squadEntity) {
         $this->flashMessenger()->addErrorMessage('Squad not found');
         return $this->redirect('frontend/user/squads');
     }
     $fileName = 'squad_file_pack_armasquads_' . $squadID;
     $zipTmpPath = tempnam(ini_get('upload_tmp_dir'), $fileName);
     $zip = new \ZipArchive();
     $zip->open($zipTmpPath, \ZipArchive::CHECKCONS);
     if (!$zip) {
         $this->flashMessenger()->addErrorMessage('Squad Package Download currently not possible');
         return $this->redirect('frontend/user/squads');
     }
     $zip->addFromString('squad.xml', file_get_contents('http://' . $_SERVER['SERVER_NAME'] . $this->url()->fromRoute('frontend/user/squads/xml', array('id' => $squadEntity->getPrivateID()))));
     if ($squadEntity->getSquadLogoPaa()) {
         $zip->addFile(ROOT_PATH . $squadEntity->getSquadLogoPaa(), basename($squadEntity->getSquadLogoPaa()));
     }
     $zip->addFromString('squad.dtd', file_get_contents(realpath(__DIR__ . '/../../../../view/squads/xml/') . '/squad.dtd'));
     //$zip->addFromString('squad.xsl',file_get_contents(realpath(__DIR__ . '/../../../../view/squads/xml/').'/squad.xsl'));
     $zip->close();
     header('Content-Type: application/octet-stream');
     header("Content-Transfer-Encoding: Binary");
     header("Content-disposition: attachment; filename=\"" . basename($fileName) . ".zip\"");
     readfile($zipTmpPath);
     sleep(1);
     @unlink($zipTmpPath);
     die;
 }
開發者ID:PrimeAltis,項目名稱:armasquads,代碼行數:33,代碼來源:SquadsController.php

示例9: save

 /**
  * Save PhpPresentation to file
  *
  * @param  string    $pFilename
  * @throws \Exception
  */
 public function save($pFilename)
 {
     if (empty($pFilename)) {
         throw new \Exception("Filename is empty.");
     }
     if (!is_null($this->presentation)) {
         // Create new ZIP file and open it for writing
         $objZip = new \ZipArchive();
         // Try opening the ZIP file
         if ($objZip->open($pFilename, \ZipArchive::CREATE) !== true) {
             if ($objZip->open($pFilename, \ZipArchive::OVERWRITE) !== true) {
                 throw new \Exception("Could not open " . $pFilename . " for writing.");
             }
         }
         // Add media
         $slideCount = $this->presentation->getSlideCount();
         for ($i = 0; $i < $slideCount; ++$i) {
             for ($j = 0; $j < $this->presentation->getSlide($i)->getShapeCollection()->count(); ++$j) {
                 if ($this->presentation->getSlide($i)->getShapeCollection()->offsetGet($j) instanceof AbstractDrawing) {
                     $imgTemp = $this->presentation->getSlide($i)->getShapeCollection()->offsetGet($j);
                     $objZip->addFromString('media/' . $imgTemp->getFilename(), file_get_contents($imgTemp->getPath()));
                 }
             }
         }
         // Add PhpPresentation.xml to the document, which represents a PHP serialized PhpPresentation object
         $objZip->addFromString('PhpPresentation.xml', $this->writeSerialized($this->presentation, $pFilename));
         // Close file
         if ($objZip->close() === false) {
             throw new \Exception("Could not close zip file {$pFilename}.");
         }
     } else {
         throw new \Exception("PhpPresentation object unassigned.");
     }
 }
開發者ID:hxsam,項目名稱:PHPPresentation,代碼行數:40,代碼來源:Serialized.php

示例10: zipFolder

 /**
  * Compresses a given folder to a ZIP file
  *
  * @param string $inputFolder the source folder that is to be zipped
  * @param string $zipOutputFile the destination file that the ZIP is to be written to
  * @return boolean whether this process was successful or not
  */
 function zipFolder($inputFolder, $zipOutputFile)
 {
     if (!extension_loaded('zip') || !file_exists($inputFolder)) {
         return false;
     }
     $zip = new ZipArchive();
     if (!$zip->open($zipOutputFile, ZIPARCHIVE::CREATE)) {
         return false;
     }
     $inputFolder = str_replace('\\', '/', realpath($inputFolder));
     if (is_dir($inputFolder) === true) {
         $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($inputFolder, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS), RecursiveIteratorIterator::SELF_FIRST);
         foreach ($files as $file) {
             $file = str_replace('\\', '/', $file);
             if (is_dir($file) === true) {
                 $dirName = str_replace($inputFolder . '/', '', $file . '/');
                 $zip->addEmptyDir($dirName);
             } else {
                 if (is_file($file) === true) {
                     $fileName = str_replace($inputFolder . '/', '', $file);
                     $zip->addFromString($fileName, file_get_contents($file));
                 }
             }
         }
     } else {
         if (is_file($inputFolder) === true) {
             $zip->addFromString(basename($inputFolder), file_get_contents($inputFolder));
         }
     }
     return $zip->close();
 }
開發者ID:jeckel420,項目名稱:Localize,代碼行數:38,代碼來源:File_IO.php

示例11: addString

 /**
  * ファイル追加(メモリ上から)
  *
  * @param string $binary 追加するファイルの內容
  * @param string $filename zip 內でのファイル名
  * @throws D9magai\Zip\Exception
  */
 public function addString($filename, $binary)
 {
     $ret = $this->zipArchive->addFromString($filename, $binary);
     if ($ret !== true) {
         throw new Exception('ファイルの追加に失敗しました');
     }
 }
開發者ID:d9magai,項目名稱:phparchive,代碼行數:14,代碼來源:Archive.php

示例12: export

 function export($params = null)
 {
     $patients = $this->Patient->getPatients($params);
     unset($this->Patient);
     $zip = new ZipArchive();
     $file = 'GaiaEHR-Patients-Export-' . time() . '.zip';
     if ($zip->open($file, ZipArchive::CREATE) !== true) {
         throw new Exception("cannot open <{$file}>");
     }
     $zip->addFromString('cda2.xsl', file_get_contents(ROOT . '/lib/CCRCDA/schema/cda2.xsl'));
     foreach ($patients as $i => $patient) {
         $patient = (object) $patient;
         $this->CCDDocument->setPid($patient->pid);
         $this->CCDDocument->createCCD();
         $this->CCDDocument->setTemplate('toc');
         $this->CCDDocument->createCCD();
         $ccd = $this->CCDDocument->get();
         $zip->addFromString($patient->pid . '-Patient-CDA' . '.xml', $ccd);
         unset($patients[$i], $ccd);
     }
     $zip->close();
     header('Content-Type: application/zip');
     header('Content-Length: ' . filesize($file));
     header('Content-Disposition: attachment; filename="' . $file . '"');
     readfile($file);
 }
開發者ID:igez,項目名稱:gaiaehr,代碼行數:26,代碼來源:DataPortability.php

示例13: archive

 /**
  * Adds file or directory to archive
  *
  * @param string $source
  * @param string $destination
  *
  * @return bool
  *
  * @throws \Exception
  */
 public function archive($source, $destination)
 {
     if (!file_exists($source)) {
         throw new \Exception('File or directory not found');
     }
     $zip = new \ZipArchive();
     if (!$zip->open($destination, \ZIPARCHIVE::OVERWRITE)) {
         throw new \Exception('Unable to open zip archive');
     }
     $source = str_replace('\\', '/', realpath($source));
     if (is_dir($source) === true) {
         $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST);
         foreach ($files as $file) {
             $file = str_replace('\\', '/', $file);
             // Ignore "." and ".." folders
             if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..'))) {
                 continue;
             }
             $file = realpath($file);
             $file = str_replace('\\', '/', $file);
             if (is_dir($file) === true) {
                 $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
             } else {
                 if (is_file($file) === true) {
                     $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file, FILE_BINARY));
                 }
             }
         }
     } else {
         if (is_file($source) === true) {
             $zip->addFromString(basename($source), file_get_contents($source, FILE_BINARY));
         }
     }
     return $zip->close();
 }
開發者ID:silverslice,項目名稱:excelpic,代碼行數:45,代碼來源:Zip.php

示例14: zipFile

function zipFile($source, $destination, $flag = '')
{
    if (!extension_loaded('zip') || !file_exists($source)) {
        return false;
    }
    $zip = new ZipArchive();
    if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
        return false;
    }
    $source = str_replace('\\', '/', realpath($source));
    if ($flag) {
        $flag = basename($source) . '/';
        //$zip->addEmptyDir(basename($source) . '/');
    }
    if (is_dir($source) === true) {
        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
        foreach ($files as $file) {
            $file = str_replace('\\', '/', realpath($file));
            if (is_dir($file) === true) {
                $zip->addEmptyDir(str_replace($source . '/', '', $flag . $file . '/'));
            } else {
                if (is_file($file) === true) {
                    $zip->addFromString(str_replace($source . '/', '', $flag . $file), file_get_contents($file));
                }
            }
        }
    } else {
        if (is_file($source) === true) {
            $zip->addFromString($flag . basename($source), file_get_contents($source));
        }
    }
    echo "Successfully Ziped Folder";
    header('Location:admin/dashboard/admin_dashboard');
    return $zip->close();
}
開發者ID:praveenpgoswami,項目名稱:codeigniter_project,代碼行數:35,代碼來源:site_backup.php

示例15: Zip

function Zip($source, $destination)
{
    if (!extension_loaded('zip') || !file_exists($source)) {
        return false;
    }
    $zip = new ZipArchive();
    if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
        return false;
    }
    $source = str_replace('\\', '/', realpath($source));
    if (is_dir($source) === true) {
        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
        foreach ($files as $file) {
            $file = str_replace('\\', '/', realpath($file));
            if (is_dir($file) === true) {
                $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
            } else {
                if (is_file($file) === true) {
                    $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
                }
            }
        }
    } else {
        if (is_file($source) === true) {
            $zip->addFromString(basename($source), file_get_contents($source));
        }
    }
    return $zip->close();
}
開發者ID:retanoj,項目名稱:webshellSample,代碼行數:29,代碼來源:405dde82997f2860c329129c847fd020.php


注:本文中的ZipArchive::addFromString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。