adam291086 Posted September 4, 2008 Share Posted September 4, 2008 i have look at the tutorial from http://www.codewalkers.com/c/a/File-Manipulation-Code/ZIP-File-Maker/ i dont understand what they want me to do with this line $filedata = "(read your file into $filedata)"; do they just want me to put in the location of the file i want to zip? Quote Link to comment https://forums.phpfreaks.com/topic/122686-solved-following-a-zip-turorial/ Share on other sites More sharing options...
Mchl Posted September 4, 2008 Share Posted September 4, 2008 They want you to put the data to be zipped into $filedata variable. Quote Link to comment https://forums.phpfreaks.com/topic/122686-solved-following-a-zip-turorial/#findComment-633540 Share on other sites More sharing options...
adam291086 Posted September 4, 2008 Author Share Posted September 4, 2008 ok i have changed tutorial and now i am using the one http://www.web-development-blog.com/archives/tutorial-create-a-zip-file-from-folders-on-the-fly/ as it accomodates folders being zipped. I am getting the error Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homepages/12/d214897219/htdocs/rubberduckiee/admin/FTP/code/zip.php on line 11 this is the code i am using <?php include ('zip.php'); $createZip = new createDirZip; $createZip->addDirectory(‘adam/’); $createZip->get_files_from_folder(‘footer/’, ‘adam/’); $fileName = ‘tmp/archive.zip’; $fd = fopen ($fileName, ‘wb’); $out = fwrite ($fd, $createZip->getZippedfile()); fclose ($fd); $createZip->forceDownload($fileName); @unlink($fileName); ?> and line 11 fclose ($fd); Quote Link to comment https://forums.phpfreaks.com/topic/122686-solved-following-a-zip-turorial/#findComment-633599 Share on other sites More sharing options...
Mchl Posted September 4, 2008 Share Posted September 4, 2008 You're using quotes wrong Wrong $createZip->get_files_from_folder(‘footer/’, ‘adam/’); Good $createZip->get_files_from_folder('footer/', 'adam/'); (They're the ones next to Enter key on standard US layout keyboard) Quote Link to comment https://forums.phpfreaks.com/topic/122686-solved-following-a-zip-turorial/#findComment-633601 Share on other sites More sharing options...
adam291086 Posted September 4, 2008 Author Share Posted September 4, 2008 still the same? Quote Link to comment https://forums.phpfreaks.com/topic/122686-solved-following-a-zip-turorial/#findComment-633602 Share on other sites More sharing options...
adam291086 Posted September 4, 2008 Author Share Posted September 4, 2008 i have realised the error is point to somehting with the extended class written by the guy who created the tutorial. Any ideas? class createDirZip extends createZip { function get_files_from_folder($directory, $put_into) { if ($handle = opendir($directory)) { while (false !== ($file = readdir($handle))) { if (is_file($directory.$file)) { $fileContents = file_get_contents($directory.$file); $this->addFile($fileContents, $put_into.$file); } elseif ($file != '.' and $file != '..' and is_dir($directory.$file)) { $this->addDirectory($put_into.$file.'/'); $this->get_files_from_folder($directory.$file.'/', $put_into.$file.'/'); } } } closedir($handle); } } Quote Link to comment https://forums.phpfreaks.com/topic/122686-solved-following-a-zip-turorial/#findComment-633608 Share on other sites More sharing options...
burn1337 Posted September 4, 2008 Share Posted September 4, 2008 a couple things I see... first I would suggest taking out the spaces right after fopen and fwrite i.e. fopen ( -> fopen(. Also I would suggest try using an absolute path for your folders i.e. /var/www/html/adam other then that idk. I have a couple ideas.. first one being that code looks so sloppy. Second either edit that code yourself.. or idk get a new one?? idk too tired to completely think lol Quote Link to comment https://forums.phpfreaks.com/topic/122686-solved-following-a-zip-turorial/#findComment-633609 Share on other sites More sharing options...
rhodesa Posted September 4, 2008 Share Posted September 4, 2008 i have realised the error is point to somehting with the extended class written by the guy who created the tutorial. Any ideas? class createDirZip extends createZip { function get_files_from_folder($directory, $put_into) { if ($handle = opendir($directory)) { while (false !== ($file = readdir($handle))) { if (is_file($directory.$file)) { $fileContents = file_get_contents($directory.$file); $this->addFile($fileContents, $put_into.$file); } elseif ($file != '.' and $file != '..' and is_dir($directory.$file)) { $this->addDirectory($put_into.$file.'/'); $this->get_files_from_folder($directory.$file.'/', $put_into.$file.'/'); } } } closedir($handle); } } there are no syntax errors in that code. post the exact error again, and the contents of the file it says the error is in. what i'm getting at is, is there more to the zip.php file then what you posted above? Quote Link to comment https://forums.phpfreaks.com/topic/122686-solved-following-a-zip-turorial/#findComment-633620 Share on other sites More sharing options...
adam291086 Posted September 4, 2008 Author Share Posted September 4, 2008 ok here is what i have zip.php <?php /** * Class to dynamically create a zip file (archive) * * @author Rochak Chauhan */ class createZip { public $compressedData = array(); public $centralDirectory = array(); // central directory public $endOfCentralDirectory = "\x50\x4b\x05\x06\x00\x00\x00\x00"; //end of Central directory record public $oldOffset = 0; /** * Function to create the directory where the file(s) will be unzipped * * @param $directoryName string * */ public function addDirectory($directoryName) { $directoryName = str_replace("\\", "/", $directoryName); $feedArrayRow = "\x50\x4b\x03\x04"; $feedArrayRow .= "\x0a\x00"; $feedArrayRow .= "\x00\x00"; $feedArrayRow .= "\x00\x00"; $feedArrayRow .= "\x00\x00\x00\x00"; $feedArrayRow .= pack("V",0); $feedArrayRow .= pack("V",0); $feedArrayRow .= pack("V",0); $feedArrayRow .= pack("v", strlen($directoryName) ); $feedArrayRow .= pack("v", 0 ); $feedArrayRow .= $directoryName; $feedArrayRow .= pack("V",0); $feedArrayRow .= pack("V",0); $feedArrayRow .= pack("V",0); $this -> compressedData[] = $feedArrayRow; $newOffset = strlen(implode("", $this->compressedData)); $addCentralRecord = "\x50\x4b\x01\x02"; $addCentralRecord .="\x00\x00"; $addCentralRecord .="\x0a\x00"; $addCentralRecord .="\x00\x00"; $addCentralRecord .="\x00\x00"; $addCentralRecord .="\x00\x00\x00\x00"; $addCentralRecord .= pack("V",0); $addCentralRecord .= pack("V",0); $addCentralRecord .= pack("V",0); $addCentralRecord .= pack("v", strlen($directoryName) ); $addCentralRecord .= pack("v", 0 ); $addCentralRecord .= pack("v", 0 ); $addCentralRecord .= pack("v", 0 ); $addCentralRecord .= pack("v", 0 ); $ext = "\x00\x00\x10\x00"; $ext = "\xff\xff\xff\xff"; $addCentralRecord .= pack("V", 16 ); $addCentralRecord .= pack("V", $this -> oldOffset ); $this -> oldOffset = $newOffset; $addCentralRecord .= $directoryName; $this -> centralDirectory[] = $addCentralRecord; } /** * Function to add file(s) to the specified directory in the archive * * @param $directoryName string * */ public function addFile($data, $directoryName) { $directoryName = str_replace("\\", "/", $directoryName); $feedArrayRow = "\x50\x4b\x03\x04"; $feedArrayRow .= "\x14\x00"; $feedArrayRow .= "\x00\x00"; $feedArrayRow .= "\x08\x00"; $feedArrayRow .= "\x00\x00\x00\x00"; $uncompressedLength = strlen($data); $compression = crc32($data); $gzCompressedData = gzcompress($data); $gzCompressedData = substr( substr($gzCompressedData, 0, strlen($gzCompressedData) - 4), 2); $compressedLength = strlen($gzCompressedData); $feedArrayRow .= pack("V",$compression); $feedArrayRow .= pack("V",$compressedLength); $feedArrayRow .= pack("V",$uncompressedLength); $feedArrayRow .= pack("v", strlen($directoryName) ); $feedArrayRow .= pack("v", 0 ); $feedArrayRow .= $directoryName; $feedArrayRow .= $gzCompressedData; $feedArrayRow .= pack("V",$compression); $feedArrayRow .= pack("V",$compressedLength); $feedArrayRow .= pack("V",$uncompressedLength); $this -> compressedData[] = $feedArrayRow; $newOffset = strlen(implode("", $this->compressedData)); $addCentralRecord = "\x50\x4b\x01\x02"; $addCentralRecord .="\x00\x00"; $addCentralRecord .="\x14\x00"; $addCentralRecord .="\x00\x00"; $addCentralRecord .="\x08\x00"; $addCentralRecord .="\x00\x00\x00\x00"; $addCentralRecord .= pack("V",$compression); $addCentralRecord .= pack("V",$compressedLength); $addCentralRecord .= pack("V",$uncompressedLength); $addCentralRecord .= pack("v", strlen($directoryName) ); $addCentralRecord .= pack("v", 0 ); $addCentralRecord .= pack("v", 0 ); $addCentralRecord .= pack("v", 0 ); $addCentralRecord .= pack("v", 0 ); $addCentralRecord .= pack("V", 32 ); $addCentralRecord .= pack("V", $this -> oldOffset ); $this -> oldOffset = $newOffset; $addCentralRecord .= $directoryName; $this -> centralDirectory[] = $addCentralRecord; } /** * Fucntion to return the zip file * * @return zipfile (archive) */ public function getZippedfile() { $data = implode("", $this -> compressedData); $controlDirectory = implode("", $this -> centralDirectory); return $data. $controlDirectory. $this -> endOfCentralDirectory. pack("v", sizeof($this -> centralDirectory)). pack("v", sizeof($this -> centralDirectory)). pack("V", strlen($controlDirectory)). pack("V", strlen($data)). "\x00\x00"; } /** * * Function to force the download of the archive as soon as it is created * * @param archiveName string - name of the created archive file */ public function forceDownload($archiveName) { $headerInfo = ''; if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } // Security checks if( $archiveName == "" ) { echo "<html><title>Public Photo Directory - Download </title><body><BR><B>ERROR:</B> The download file was NOT SPECIFIED.</body></html>"; exit; } elseif ( ! file_exists( $archiveName ) ) { echo "<html><title>Public Photo Directory - Download </title><body><BR><B>ERROR:</B> File not found.</body></html>"; exit; } header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: application/zip"); header("Content-Disposition: attachment; filename=".basename($archiveName).";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($archiveName)); readfile("$archiveName"); } } class createDirZip extends createZip { function get_files_from_folder($directory, $put_into) { if ($handle = opendir($directory)) { while (false !== ($file = readdir($handle))) { if (is_file($directory.$file)) { $fileContents = file_get_contents($directory.$file); $this->addFile($fileContents, $put_into.$file); } elseif ($file != '.' and $file != '..' and is_dir($directory.$file)) { $this->addDirectory($put_into.$file.'/'); $this->get_files_from_folder($directory.$file.'/', $put_into.$file.'/'); } } } closedir($handle); } } ?> how i call on zip.php, file called test_zip.php <?php include ('zip.php'); $createZip = new createDirZip; $createZip->addDirectory('themes/'); $createZip->get_files_from_folder('footer/', 'themes/'); $fileName = ‘tmp/archive.zip’; $fd = fopen ($fileName, ‘wb’); $out = fwrite ($fd, $createZip->getZippedfile()); fclose ($fd); $createZip->forceDownload($fileName); @unlink($fileName); ?> error Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homepages/12/d214897219/htdocs/rubberduckiee/admin/FTP/code/zip.php on line 11 Quote Link to comment https://forums.phpfreaks.com/topic/122686-solved-following-a-zip-turorial/#findComment-633628 Share on other sites More sharing options...
rhodesa Posted September 4, 2008 Share Posted September 4, 2008 did you solve this? ...by the looks of it, you are still using PHP4...is this true? Quote Link to comment https://forums.phpfreaks.com/topic/122686-solved-following-a-zip-turorial/#findComment-633671 Share on other sites More sharing options...
adam291086 Posted September 4, 2008 Author Share Posted September 4, 2008 i did solve by finding a different tutorial that already includes the downloading of the file and it all works now. Thanks for your help though Quote Link to comment https://forums.phpfreaks.com/topic/122686-solved-following-a-zip-turorial/#findComment-633754 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.