/    Sign up×
Community /Pin to ProfileBookmark

downloading images

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

to post a comment
PHP

16 Comments(s)

Copy linkTweet thisAlerts:
@MrCoderFeb 29.2008 — Increase your memory limit in the php.ini file.
Copy linkTweet thisAlerts:
@jrthor2authorFeb 29.2008 — Which memory limit? I tried setting the post_max_size to 100M, but that didn't help anything.
Copy linkTweet thisAlerts:
@jrthor2authorFeb 29.2008 — 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?
Copy linkTweet thisAlerts:
@jrthor2authorFeb 29.2008 — Could it be something with the php file? Here is the code it is failing on (the line that has $this -> eof_ctrl_dir.):
[code=php]
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
"x00x00"; // .zip file comment length
}
[/code]
Copy linkTweet thisAlerts:
@MrCoderFeb 29.2008 — 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?[/QUOTE]

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.
Copy linkTweet thisAlerts:
@jrthor2authorFeb 29.2008 — 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?
Copy linkTweet thisAlerts:
@MrCoderFeb 29.2008 — 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?[/QUOTE]



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?
Copy linkTweet thisAlerts:
@jrthor2authorFeb 29.2008 — It is attached, too long to post.

[upl-file uuid=cc3ce33a-b3ce-465e-b57e-dd73344ec62a size=10kB]plog-download.txt[/upl-file]
Copy linkTweet thisAlerts:
@MrCoderFeb 29.2008 — 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)?
Copy linkTweet thisAlerts:
@jrthor2authorFeb 29.2008 — I'm not following you, but I may. What would I do?
Copy linkTweet thisAlerts:
@MrCoderFeb 29.2008 — 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.
Copy linkTweet thisAlerts:
@jrthor2authorFeb 29.2008 — 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?
Copy linkTweet thisAlerts:
@MrCoderFeb 29.2008 — 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?[/QUOTE]

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..
Copy linkTweet thisAlerts:
@jrthor2authorFeb 29.2008 — 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.
Copy linkTweet thisAlerts:
@MrCoderFeb 29.2008 — 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.

[code=php]
$myFileList = "file1.txt file2.jpg";
$zipFileName = "MyZipFile";

exec("zip ".$zipFileName." ".$myFileList);
[/code]

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.
[code=php]
exec("zip MyZipFile myfiles/*");
[/code]


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 ?
×

Success!

Help @jrthor2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...