Click to See Complete Forum and Search --> : downloading images


jrthor2
02-28-2008, 01:04 PM
I have a site that has a photo gallery on, that allows users to download entire albums. There is one album that has about 50 pics or so, that when you download it as a zip, it says the file is not a valid zip archive. The error log has the below error:

[28-Feb-2008 11:53:07] PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 19040716 bytes) in /home/zluthorg/public_html/photo_gallery/plog-download.php on line 184

Any ideas on how to fix this? Is this because there are too many files making the zip file too large? The directory size looks to be 20 megs, so that's how big the zip file would be.

thanks

MrCoder
02-29-2008, 04:55 AM
Increase your memory limit in the php.ini file.

jrthor2
02-29-2008, 05:30 AM
Which memory limit? I tried setting the post_max_size to 100M, but that didn't help anything.

MrCoder
02-29-2008, 05:39 AM
"memory_limit" (http://uk.php.net/manual/en/ini.core.php)

jrthor2
02-29-2008, 06:40 AM
i updated the memory_limit from 20M to 50M, but I still get the same error. The php.ini file is in my photo_albums directory, so it should be using that one, right?

jrthor2
02-29-2008, 06:43 AM
Could it be something with the php file? Here is the code it is failing on (the line that has $this -> eof_ctrl_dir.):

function file() { // dump out file
$data = implode("", $this -> datasec);
$ctrldir = implode("", $this -> ctrl_dir);

return
$data.
$ctrldir.
$this -> eof_ctrl_dir.
pack("v", sizeof($this -> ctrl_dir)). // total # of entries "on this disk"
pack("v", sizeof($this -> ctrl_dir)). // total # of entries overall
pack("V", strlen($ctrldir)). // size of central dir
pack("V", strlen($data)). // offset to start of central dir
"\x00\x00"; // .zip file comment length
}

MrCoder
02-29-2008, 06:46 AM
i updated the memory_limit from 20M to 50M, but I still get the same error. The php.ini file is in my photo_albums directory, so it should be using that one, right?

Thats something you need to find out, did you restart Apache when you edited the php.ini file?

If you did edit the right file and restarted Apache then the error message should of gone, or at least changed to reflect the new limit.

Changing the limit to -1 will remove any memory limit.

You may not have the ability to override the memory limit if using shared hosting.

jrthor2
02-29-2008, 06:55 AM
Ah, I am using shared hosting, so I can't restart Apache. Maybe that's my issue.

But, the error says:

Allowed memory size of 67108864

Doesn't this mean 67 megs of memory? And it says my script tried to allocate 19040716 bytes, which is less than the Allowed memory above, right?

MrCoder
02-29-2008, 07:03 AM
Ah, I am using shared hosting, so I can't restart Apache. Maybe that's my issue.

But, the error says:

Allowed memory size of 67108864

Doesn't this mean 67 megs of memory? And it says my script tried to allocate 19040716 bytes, which is less than the Allowed memory above, right?


Allowed memory size of {MAX MEMORY} bytes exhausted (tried to allocate {BYTES OVER THE MAX MEMORY THAT THE SCRIPT NEEDED} bytes)

So you were trying to allocate 67108864 + 19040716 bytes

67108864 / 1024 / 1024 = 64 Meg
86149580 / 1024 / 1024 = 82.15 Meg (More then the 64 Meg Limit)

Paste your PHP code, maybe we can optimize it?

jrthor2
02-29-2008, 07:18 AM
It is attached, too long to post.

MrCoder
02-29-2008, 07:24 AM
Do you have access to any of the low level commands such as exec and system?

Why not just use (INSERT LINUX/WINDOWS ZIPPIER PROGRAM NAME)?

jrthor2
02-29-2008, 07:25 AM
I'm not following you, but I may. What would I do?

MrCoder
02-29-2008, 07:32 AM
For example if I wanted to create a compressed file in Linux I would run..
tar -cf myArcive.tar files

Then compress it with gzip
gzip myArcive.tar

This would give me a compressed file called myArchive.tar.gz

The above commands should be accessible via an exec() or system() function call.

jrthor2
02-29-2008, 07:49 AM
I think I can use those commands. could you show me how to zip them as a .zip file? Also, what would this replace in my code?

MrCoder
02-29-2008, 07:58 AM
I think I can use those commands. could you show me how to zip them as a .zip file? Also, what would this replace in my code?

I don't know how you go about making a .zip file in Linux, but I'm 100% sure there is a very easy way of doing it..

jrthor2
02-29-2008, 08:03 AM
Ok, if I find a way, what do I replace in my plog-download.php file?

I just found a way, and ran it on my server, here''s an example:

zip rock dino.txt bambam.txt wilma.txt

creates the file rock.zip

Also, Zip can compress folders and their contents, eg:

zip myzip myfiles/*

So, how could I use this in my download script?

Thanks for all the help.

MrCoder
02-29-2008, 08:16 AM
Im going to assume there is a part in your code that builds a list of files that need compressing?

You need to find this part of the code and build up a command line.

Then you would do something like this.


$myFileList = "file1.txt file2.jpg";
$zipFileName = "MyZipFile";

exec("zip ".$zipFileName." ".$myFileList);

Building the $myFileList is going to be the tricky bit.
You may not need to do this since you may always be zipping the same folder contents. In this case something like this would work for you.

exec("zip MyZipFile myfiles/*");


Make sure your chmod / chown permissions are correct and everything should work for you (unless your web host has disabled exec() or system())

Gratz on finding the command :)