Doc #76235 [NEW]: imagejpeg does not always return false on error

From: Date: Wed, 18 Apr 2018 12:50:19 +0000
Subject: Doc #76235 [NEW]: imagejpeg does not always return false on error
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-15602@lists.php.net to get a copy of this message
From: inkredibl at gmail dot com Operating system: Mac PHP version: 7.1.16 Package: Documentation problem Bug Type: Documentation Problem Bug description:imagejpeg does not always return false on error Description: ------------ Whenever out of space situation happens on a drive imagejpeg() does not necessarily return false when it fails to write the image to disk. This creates a problem when you need to handle errors since no error can be detected in this case. I'm fine with it not working all the time but the documentation needs to mention this somewhere. Fixing this would also be nice but still it needs to be mentioned that this is going on so that people can write valid code. If you could get a disk with tiny amounts of available space and save images on it this will happen whenever there's not enough space on the drive to save the whole image. The workaround is to use: ob_start(); imagejpeg($img, null); $content = ob_get_clean(); $result = (file_put_contents('file.jpg', $content) == strlen($content)); Test script: --------------- <?php $img = imagecreate(4000, 4000); $result = imagejpeg($img, 'file.jpg', 100); // $result will be true even if the image is truncated or in some cases even totally empty (my guess is it depends on the file system) var_export($result) -- Edit bug report at https://bugs.php.net/bug.php?id=76235&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76235&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76235&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76235&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=76235&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=76235&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=76235&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=76235&r=needscript Try newer version: https://bugs.php.net/fix.php?id=76235&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=76235&r=support Expected behavior: https://bugs.php.net/fix.php?id=76235&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=76235&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=76235&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=76235&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76235&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=76235&r=dst IIS Stability: https://bugs.php.net/fix.php?id=76235&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=76235&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=76235&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=76235&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=76235&r=mysqlcfg

« previous php.doc.bugs (#15602) next »