本文整理汇总了PHP中zip_packer::archive_to_pathname方法的典型用法代码示例。如果您正苦于以下问题:PHP zip_packer::archive_to_pathname方法的具体用法?PHP zip_packer::archive_to_pathname怎么用?PHP zip_packer::archive_to_pathname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zip_packer
的用法示例。
在下文中一共展示了zip_packer::archive_to_pathname方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pack_files
function pack_files($filesforzipping) {
global $CFG;
$tempzip = tempnam($CFG->tempdir . '/', 'local_mail_');
$zipper = new zip_packer();
if ($zipper->archive_to_pathname($filesforzipping, $tempzip)) {
return $tempzip;
}
return false;
}
示例2: archive_directory
public static function archive_directory($directory_path, $file_path)
{
$files = array();
$directory_path = rtrim($directory_path, '/');
$entries = scandir($directory_path);
foreach ($entries as $entry) {
if ($entry != '.' && $entry != '..') {
$path = $directory_path . '/' . $entry;
$files[$entry] = $path;
}
}
$zipper = new zip_packer();
$result = $zipper->archive_to_pathname($files, $file_path);
return $result;
}
示例3: pack_files
/**
* Generate zip file from array of given files.
*
* @param array $filesforzipping - array of files to pass into archive_to_pathname.
* This array is indexed by the final file name and each
* element in the array is an instance of a stored_file object.
* @return path of temp file - note this returned file does
* not have a .zip extension - it is a temp file.
*/
protected function pack_files($filesforzipping)
{
global $CFG;
// Create path for new zip file.
$tempzip = tempnam($CFG->tempdir . '/', 'assignment_');
// Zip files.
$zipper = new zip_packer();
if ($zipper->archive_to_pathname($filesforzipping, $tempzip)) {
return $tempzip;
}
return false;
}
示例4: assignment_pack_files
/**
* generate zip file from array of given files
* @param array $filesforzipping - array of files to pass into archive_to_pathname
* @return path of temp file - note this returned file does not have a .zip extension - it is a temp file.
*/
function assignment_pack_files($filesforzipping) {
global $CFG;
//create path for new zip file.
$tempzip = tempnam($CFG->dataroot.'/temp/', 'assignment_');
//zip files
$zipper = new zip_packer();
if ($zipper->archive_to_pathname($filesforzipping, $tempzip)) {
return $tempzip;
}
return false;
}
示例5: download_items
/**
* @param $list array List of item id's to download. Empty array means all files.
* @return void
*/
public function download_items(array $list = array())
{
global $CFG, $DB;
// More efficient to load this here.
require_once $CFG->libdir . '/filelib.php';
$filesforzipping = array();
$fs = get_file_storage();
$filename = clean_filename('mediagallery-export-' . $this->record->name . '.zip');
$files = $fs->get_area_files($this->get_collection()->context->id, 'mod_mediagallery', 'item', false, 'id', false);
$items = $this->get_items();
$keyed = array_flip($list);
foreach ($files as $file) {
$selected = isset($keyed[$file->get_itemid()]) || empty($list);
if ($selected && isset($items[$file->get_itemid()])) {
$filesforzipping[$file->get_filename()] = $file;
}
}
if (empty($filesforzipping)) {
return;
}
$tempzip = tempnam($CFG->tempdir . '/', 'mediagallery_');
$zipper = new \zip_packer();
$zipper->archive_to_pathname($filesforzipping, $tempzip);
// Send file and delete after sending.
send_temp_file($tempzip, $filename);
}
示例6: view_bulk_certificates
//.........这里部分代码省略.........
echo $OUTPUT->render($select);
echo '<br>';
echo '<form id="bulkissue" name="bulkissue" method="post" action="view.php">';
echo html_writer::label(get_string('bulkaction', 'simplecertificate'), 'menutype', true);
echo ' ';
$selectoptions = array('pdf' => get_string('onepdf', 'simplecertificate'), 'zip' => get_string('multipdf', 'simplecertificate'), 'email' => get_string('sendtoemail', 'simplecertificate'));
echo html_writer::select($selectoptions, 'type', 'pdf');
$table = new html_table();
$table->width = "95%";
$table->tablealign = "center";
//strgrade
$table->head = array(' ', get_string('fullname'), get_string('grade'));
$table->align = array("left", "left", "center");
$table->size = array('1%', '89%', '10%');
foreach ($users as $user) {
$canissue = $this->can_issue($user, $issuelist != 'allusers');
if (empty($canissue)) {
$chkbox = html_writer::checkbox('selectedusers[]', $user->id, false);
$name = $OUTPUT->user_picture($user) . fullname($user);
$table->data[] = array($chkbox, $name, $this->get_grade($user->id));
}
}
$downloadbutton = $OUTPUT->single_button($url->out_as_local_url(false, array('action' => 'download')), get_string('bulkbuttonlabel', 'simplecertificate'));
echo $OUTPUT->paging_bar($usercount, $page, $perpage, $url);
echo '<br />';
echo html_writer::table($table);
echo html_writer::tag('div', $downloadbutton, array('style' => 'text-align: center'));
echo '</form>';
} else {
if ($action == 'download') {
$type = $url->get_param('type');
// Calculate file name
$filename = str_replace(' ', '_', clean_filename($this->get_instance()->coursename . ' ' . get_string('modulenameplural', 'simplecertificate') . ' ' . strip_tags(format_string($this->get_instance()->name, true)) . '.' . strip_tags(format_string($type, true))));
switch ($type) {
//One pdf with all certificates
case 'pdf':
$pdf = $this->create_pdf_object();
foreach ($users as $user) {
$canissue = $this->can_issue($user, $issuelist != 'allusers');
if (empty($canissue)) {
//To one pdf file
$issuecert = $this->get_issue($user);
$this->create_pdf($issuecert, $pdf, true);
//Save certificate PDF
if (!$this->issue_file_exists($issuecert)) {
//To force file creation
$issuecert->haschage = true;
$this->get_issue_file($issuecert);
}
}
}
$pdf->Output($filename, 'D');
break;
//One zip with all certificates in separated files
//One zip with all certificates in separated files
case 'zip':
$filesforzipping = array();
foreach ($users as $user) {
$canissue = $this->can_issue($user, $issuelist != 'allusers');
if (empty($canissue)) {
$issuecert = $this->get_issue($user);
if ($file = $this->get_issue_file($issuecert)) {
$fileforzipname = $file->get_filename();
$filesforzipping[$fileforzipname] = $file;
} else {
error_log(get_string('filenotfound', 'simplecertificate'));
print_error(get_string('filenotfound', 'simplecertificate'));
}
}
}
$tempzip = $this->create_temp_file('issuedcertificate_');
//zipping files
$zipper = new zip_packer();
if ($zipper->archive_to_pathname($filesforzipping, $tempzip)) {
//send file and delete after sending.
send_temp_file($tempzip, $filename);
}
break;
case 'email':
foreach ($users as $user) {
$canissue = $this->can_issue($user, $issuelist != 'allusers');
if (empty($canissue)) {
$issuecert = $this->get_issue($user);
if ($this->get_issue_file($issuecert)) {
$this->send_certificade_email($issuecert);
} else {
error_log(get_string('filenotfound', 'simplecertificate'));
print_error('filenotfound', 'simplecertificate');
}
}
}
$url->remove_params('action', 'type');
redirect($url, get_string('emailsent', 'simplecertificate'), 5);
break;
}
exit;
}
}
echo $OUTPUT->footer();
}
示例7: badges_download
/**
* Download all user badges in zip archive.
*
* @param int $userid ID of badge owner.
*/
function badges_download($userid)
{
global $CFG, $DB;
$context = context_user::instance($userid);
$records = $DB->get_records('badge_issued', array('userid' => $userid));
// Get list of files to download.
$fs = get_file_storage();
$filelist = array();
foreach ($records as $issued) {
$badge = new badge($issued->badgeid);
// Need to make image name user-readable and unique using filename safe characters.
$name = $badge->name . ' ' . userdate($issued->dateissued, '%d %b %Y') . ' ' . hash('crc32', $badge->id);
$name = str_replace(' ', '_', $name);
if ($file = $fs->get_file($context->id, 'badges', 'userbadge', $issued->badgeid, '/', $issued->uniquehash . '.png')) {
$filelist[$name . '.png'] = $file;
}
}
// Zip files and sent them to a user.
$tempzip = tempnam($CFG->tempdir . '/', 'mybadges');
$zipper = new zip_packer();
if ($zipper->archive_to_pathname($filelist, $tempzip)) {
send_temp_file($tempzip, 'badges.zip');
} else {
debugging("Problems with archiving the files.", DEBUG_DEVELOPER);
die;
}
}
示例8: mediaboard_pack_files
function mediaboard_pack_files($filesforzipping)
{
global $CFG;
//create path for new zip file.
$tempzip = tempnam($CFG->tempdir . '/', 'mediaboard_');
//zip files
$zipper = new zip_packer();
if ($zipper->archive_to_pathname($filesforzipping, $tempzip)) {
return $tempzip;
}
return false;
}
示例9:
$path = '';
if (0 === strpos($filename, 'form-')) {
$path = get_string('questionforms', 'offlinequiz');
} else {
if (0 === strpos($filename, 'answer-')) {
$path = get_string('answerforms', 'offlinequiz');
} else {
$path = get_string('correctionforms', 'offlinequiz');
}
}
$path = clean_filename($path);
$filelist[$path . '/' . $filename] = $file;
}
}
$zipper = new zip_packer();
if ($zipper->archive_to_pathname($filelist, $tempzip)) {
send_temp_file($tempzip, $zipfilename);
}
}
// Print the page header.
echo $OUTPUT->header();
// Print the offlinequiz name heading and tabs for teacher.
$currenttab = 'createofflinequiz';
require 'tabs.php';
$hasscannedpages = offlinequiz_has_scanned_pages($offlinequiz->id);
if ($offlinequiz->grade == 0) {
echo '<div class="linkbox"><strong>';
echo $OUTPUT->notification(get_string('gradeiszero', 'offlinequiz'), 'notifyproblem');
echo '</strong></div>';
}
// Preview.
示例10: packaging_execute
/**
* Packages the entire flavour and returns it
* @todo Add a checksum
*/
public function packaging_execute()
{
global $USER, $CFG;
$errorredirect = $this->url . '?sesskey=' . sesskey();
// Getting selected data
$selectedingredients = $this->get_ingredients_from_form();
if (!$selectedingredients) {
redirect($errorredirect, get_string('nothingselected', 'local_flavours'), 2);
}
// Flavour data
$form = new flavours_packaging_form($this->url);
if (!($data = $form->get_data())) {
print_error('errorpackaging', 'local_flavours');
}
// Starting <xml>
$xmloutput = new memory_xml_output();
$xmltransformer = new flavours_xml_transformer();
$xmlwriter = new flavours_xml_writer($xmloutput, $xmltransformer);
$xmlwriter->start();
$xmlwriter->begin_tag('flavour');
$xmlwriter->full_tag('name', $data->name);
$xmlwriter->full_tag('description', $data->description);
$xmlwriter->full_tag('author', $data->author);
$xmlwriter->full_tag('timecreated', time());
$xmlwriter->full_tag('sourceurl', $CFG->wwwroot);
$xmlwriter->full_tag('sourcemoodlerelease', $CFG->release);
$xmlwriter->full_tag('sourcemoodleversion', $CFG->version);
// Random code to store the flavour data
$hash = sha1('flavour_' . $USER->id . '_' . time());
$flavourpath = $this->flavourstmpfolder . '/' . $hash;
if (file_exists($flavourpath) || !mkdir($flavourpath, $CFG->directorypermissions)) {
print_error('errorpackaging', 'local_flavours');
}
// Adding the selected ingredients data
$xmlwriter->begin_tag('ingredient');
foreach ($selectedingredients as $ingredienttype => $ingredientsdata) {
// instance_ingredient_type gets a new flavours_ingredient_* object
$type = $this->instance_ingredient_type($ingredienttype);
$xmlwriter->begin_tag($type->id);
// It executes the ingredient type specific actions to package
$type->package_ingredients($xmlwriter, $flavourpath, $ingredientsdata);
$xmlwriter->end_tag($type->id);
}
$xmlwriter->end_tag('ingredient');
// Finishing flavour index
$xmlwriter->end_tag('flavour');
$xmlwriter->stop();
$flavourxml = $xmloutput->get_allcontents();
// Creating the .xml with the flavour info
$xmlfilepath = $flavourpath . '/flavour.xml';
if (!($xmlfh = fopen($xmlfilepath, 'w'))) {
print_error('errorpackaging', 'local_flavours');
}
fwrite($xmlfh, $flavourxml);
fclose($xmlfh);
// Flavour contents compression
$packer = new zip_packer();
$zipfilepath = $this->flavourstmpfolder . '/' . $hash . '/flavour_' . date('Y-m-d') . '.zip';
if (!$packer->archive_to_pathname(array('flavour' => $flavourpath), $zipfilepath)) {
print_error('errorpackaging', 'local_flavours');
}
session_get_instance()->write_close();
send_file($zipfilepath, basename($zipfilepath));
// To avoid the html headers and all the print* stuff
die;
}
示例11: pack_files
private function pack_files($filesforzipping)
{
global $CFG;
// Create path for new zip file.
$tempzip = tempnam($CFG->dataroot . '/temp/', 'publication_');
// Zip files.
$zipper = new zip_packer();
if ($zipper->archive_to_pathname($filesforzipping, $tempzip)) {
return $tempzip;
}
return false;
}
示例12: finish
/**
* Exporting is done, wrap things up.
*
* @throws \coding_exception
* @return void
*/
public function finish()
{
global $CFG;
require_once $CFG->libdir . '/filelib.php';
$this->format->close();
if ($this->attachments) {
$zipname = pathinfo($this->exportfile, PATHINFO_FILENAME) . '.zip';
$zippath = $this->tempdirectory . '/' . $zipname;
$zip = new \zip_packer();
if (!$zip->archive_to_pathname($this->archivefiles, $zippath)) {
throw new \coding_exception('Failed to create zip archive');
}
send_file($zippath, $zipname, 0, 0, false, true, '', true);
} else {
send_file($this->exportfile, pathinfo($this->exportfile, PATHINFO_BASENAME), 0, 0, false, true, '', true);
}
fulldelete($this->tempdirectory);
}
示例13: tempnam
}
}
}
}
} else {
if ($material_name == 'folder') {
//for folder
if (!($tmp_files = $fs->get_file($material_infos->context->id, 'mod_' . $material_name, 'content', '0', '/', '.'))) {
$tmp_files = null;
}
$sect_id = $material_infos->sectionnum;
// Chong 20141119
if ($ccsectid == 0) {
$files_zum_downloaden[$filename . '/' . $subfolder . '_' . $sect_id . '/' . str_replace($ersetzen_mit, $ersetzt, clean_filename($material_infos->name))] = $tmp_files;
} else {
if ($ccsectid == $sect_id) {
$files_zum_downloaden[$filename . '/' . str_replace($ersetzen_mit, $ersetzt, clean_filename($material_infos->name))] = $tmp_files;
}
}
}
}
// Chong 20141119
}
}
//zip files
$tempzip = tempnam($CFG->tempdir . '/', get_string('dm_materials', 'block_material_download') . '_' . $course->shortname);
$zipper = new zip_packer();
$filename = $filename . ".zip";
if ($zipper->archive_to_pathname($files_zum_downloaden, $tempzip)) {
send_temp_file($tempzip, $filename);
}