当前位置: 首页>>代码示例>>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;未经允许,请勿转载。