Source for file archive.php
Documentation is available at archive.php
* Command line file archiving script.
* This is a command line script which reads information from the HRDI_Downloads
* table and compresses the necessary files into an archive. The archive is then
* moved to a web accessible directory, where the polling script notices it and
* makes it available for download. The PclZip library is used for the Zip file
* creation. The library page is located at:
* http://www.phpconcept.net/pclzip/
* This file is part of HRDIODB.
* HRDIODB is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* HRDIODB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with HRDIODB; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/** Configuration file */
require_once("conf.php");
/** HRDI database class */
require_once("hrdi_db_class.php");
require_once("download_class.php");
/** PclZip library, http://www.phpconcept.net/pclzip/ */
require_once ("pclzip/pclzip.lib.php");
// Create class instances
// Check the number of arguments. One argument is allowed.
print "Error: This script takes one argument\n";
// Make sure that the download id is valid
print "Error: Download id must be a number!\n";
// Set time limit to 0 so that the script never times out
// Set the memory limit so that we don't pass it
ini_set('memory_limit', ($max_archive_size + 1). "M");
// Get file name and the list of files to compress
list ($file, $files) = $download->get_download_info($id);
$error_file = "$temp_prefix/$file.error";
// Figure out the temporary and destination file locations
$tempfile = "$temp_prefix/$file";
$destfile = "$archive_prefix/$file";
/* Create a new PclZip class instance. This is the representation of the Zip
$archive = new PclZip($tempfile);
// Create the actual Zip archive
$status = $archive->create($files, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_ADD_PATH, 'hrdifiles/');
// Check the status of the archive
write_error_file($error_file, "Archive creation failed: ". $archive->errorInfo());
// If archive is not valid, delete it
// Move the file to its final, web-accessible destination
if (!rename($tempfile, $destfile)) {
write_error_file($error_file, "Archive script was unable to move the file to its destination.");
// If we couldn't move the archive, delete it
* Writes an error to a file.
* This function does what {@link PHP_MANUAL#file_put_contents}
* does in PHP 5. It takes a file name, opens it in append mode, writes the
* message and closes the file.
* @param string $error_file The error file name
* @param string $message The error message to write
$fh = fopen($error_file, 'a');
|