Jump to content

Help with fixing a simple syntax error


Fitz

Recommended Posts

Hi,

 

I've coded the following script which is meant to dump files from my server into a created .zip file, then allow the user to download them. The following script works successfully on one server I have, but simply displays this error on another server where it is uploaded:

 

Parse error: syntax error, unexpected ')', expecting '(' in ************************ on line 13

 

For reference, line 13 is this:

$zipobject->open("images.zip", ZipArchive::OVERWRITE);

 

Here is the complete code:

<?php
//Defines header
header("Content-type: application/zip"); 
header('Content-Disposition: attachment; filename="Screen_Images.zip"');

//Creates "images.zip" file for writing
$ourFileName = "images.zip";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);

//Creates a new ZipArchive from the previously created "images.zip" file
$zipobject = new ZipArchive();
$zipobject->open("images.zip", ZipArchive::OVERWRITE);

//Defines some variables
$set_array = array('maintenance','operations');
$main_array = array('main1','main2','main3','main4','main5');
$images_array = array('image1.bmp','image2.bmp','image3.bmp','image4.bmp','image5.bmp','image6.bmp','image7.bmp','image8.bmp','image9.bmp','image10.bmp');

//Adds multiple files to "images.zip" if they exist
for ($x = 0; $x < sizeof($set_array); $x++) {
for ($y = 0; $y < sizeof($main_array); $y++) {
for ($z = 0; $z < sizeof($images_array); $z++) {
$filename2[$x][$y][$z] = $_GET['account']."/".$set_array[$x]."/".$main_array[$y]."/".$images_array[$z];
if (file_exists($filename2[$x][$y][$z])) {
$zipobject->addFile($filename2[$x][$y][$z]);
}
}
}
}
$zipobject->addFile("screen_creator.exe", $_GET['account']."/screen_creator.exe");
$zipobject->addFile($_GET['account']."/Convert_To_Scr.bat");

//Closes the Zip file and echos it, which displays a download box for the user to download the packaged "images.zip" file
$zipobject->close();
echo file_get_contents("images.zip");

//Deletes the "images.zip" file from the server
unlink($ourFileName);
?>

 

Again, it works perfectly on one server, but displays the above syntax error on another. I need it to work on both servers, but I can't figure out the meaning of the error as it appears that the ')' should be there.

 

Help with this would be greatly appreciated, thanks!  :)

 

 

Link to comment
https://forums.phpfreaks.com/topic/148678-help-with-fixing-a-simple-syntax-error/
Share on other sites

Thanks for the replies! :)

 

I actually found out that it gets rid of the error if I simply leave out the OVERWRITE function and make line 13:

$zipobject->open("images.zip");

 

According to the PHP manual (http://us.php.net/manual/en/function.ziparchive-open.php), I was in fact using the OVERWRITE property correctly, however discovered that this property wasn't really even needed in the script since because it already create a new zip folder every time with fopen, there's no need to overwrite anything.

 

But, I'm afraid I have a new problem. Everything is still working perfectly on my first server, and the second server now is able to download the .zip file without errors due to the above changes I made.

 

However, whenever I try to open the .zip file downloaded from the second server, I get this error:

The Compressed (zipped) is Invalid or Corrupted.

After doing a quick check, I found that my second server is on PHP Version 4.4.9 - however, apparently the "ZipArchive::addFile" command I am using requires PHP 5.2.0.

 

So I suppose my new question is - is there any command similar to "ZipArchive::addFile" (http://us.php.net/manual/en/function.ziparchive-addfile.php) that will work in PHP 4.4.9? Or, if not - is there any way that I'm able to allow a user to download a .zip file which contains multiple files from the server, in PHP 4.4.9?

 

Thanks in advance!  :)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.