MyBB Community Forums

Full Version: 30 MB Attachment causes problems
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I don't know if this is just my host or anything...
So I'd like somebody to confirm the following bug:

I uploaded a 30MB attachment, it's correctly uploaded, i checked via FTP.

But if somebody downloads attachment it's only 203 Byte.

It also takes the space of my attchments and is written down there with 30MB.

Thanks for reading.

EDIT: Zip-file...
Link to this attachment, and a test account if login is required to download it?
I uploaded another attachment of similar size here:
http://www.zaiendo.de/board/showthread.php?tid=212
You'll have to login with the following test account:
Username: test Password: testest

Thanks for looking into it!
I confirmed my suspicions. If you open the zip you downloaded in an editor like notepad, you find the following error:
Quote:<br />
<b>Fatal error</b>: Allowed memory size of 67108864 bytes exhausted (tried to allocate 28835840 bytes) in <b>/users/zaiendo/www/board/attachment.php</b> on line <b>128</b><br />

You need to increase the memory limit in your php.ini if you have access to it. Otherwise, contact your webhost.
My Max. Upload / POST Limit is 128M / 132M according to MyBB.
Direct downloads of ZIP-files of this size are working properly.
What exactly causes this error?

I'll contact my webhost for php.ini change, thnak you Dennis TT!
In your PHP Info page, you can search for "memory_limit" - it's too low for PHP to process the attachment.
memory_limit 64M 32M
I don't see a problem here Sad
PHP says it's too low for its needs Toungue
attachment.php apparently uses file_get_contents() which loads the whole file into memory. Usually this is not a problem as attachments are supposed to be smallish. With huge attachments, it will break any memory limit easily. In your case 64MB were exhausted when trying to allocate 27.5MB.

If you need support for huge attachments but can't increase PHP memory limit, you have two options... number one would be to get rid of file_get_contents() in attachment.php and instead let your webserver handle sending the file with a sendfile header (must be supported by the webserver, e.g. it's an Apache extension). Or change MyBB so that it gives direct download links to the file, i.e. bypass PHP altogether when downloading attachments.

A third option may be to not read the whole file in a single file_get_contents() call, but only read e.g. 1MB a time in a loop and echo that. I'm not sure if that actually helps with PHP memory usage as the echoed output still has to be held somewhere while you're downloading it. It may be easier on memory anyway as the file isn't in memory twice at a time (once as a string, once the echoed copy).
Thanks you two, I guess I'll do direct downloads in this case.
Best regards