Weirdness killing script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Weirdness killing script

Post by mchaggis »

Hi,

I have a wierdness that is baffling me.

Code: Select all

<?php

print "Before";
$img = imagecreatefromjpeg ( $filename );
print "After";
?>
$filename is a 600k jpeg file.

Now executing the above does nothing, zip, nada. It should just print the words Before and After, but what appears to be happening is the script just dies and nothing is printed, if I place exit after the first print, then the script actually runs and just prints Before.


I have seen this before with some other code, that I am just using readfile() or passthru() of various file formats and sizes. I just put it down to the files being corrupted during uploading, but this doesn't actually seem to be the case?

Very confused. :?
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Post by mchaggis »

Ok, a little more investigation and i find the following... doh!
cs at kainaw dot com
01-Nov-2004 07:09
The ImageCreateFromJPEG() function is capable of throwing an emalloc() error. If this happens, the script will die, but the error will be in your error logs. You should ensure that you have memory available before creating a large image from a jpeg file.
If I edit the php.ini file entry for:

Code: Select all

memory_limit
It now works, but I can't see how a 600k images is requiring so much memory???
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Re: Weirdness killing script

Post by phpScott »

mchaggis wrote:Hi,

Code: Select all

<?php

print "Before";
$img = imagecreatefromjpeg ( $filename );
print "After";
?>
i would suggest doing a if(file_exists($filename)) before loading the file as it may be crashing because the file doesn't exist where you think it should be.
second thing is to check to make sure that you have the GD2 library loaded and in the right place.
thirdly is your display_errors on in your php.ini file? As hopefully you are getting some sort of error message

[edit]
ignore me then
[/edit]
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
Hi,
It now works, but I can't see how a 600k images is requiring so much memory???
To work with the .jpg file, it will have to be uncompressed. That would be approximately 25MB or even more php has to work with - and memory limit is 8MB by default.

djot
-
Post Reply