|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2018-04-18 14:29 UTC] cmb@php.net
-Status: Open
+Status: Analyzed
-Package: Documentation problem
+Package: GD related
-Assigned To:
+Assigned To: cmb
[2018-04-18 14:29 UTC] cmb@php.net
[2018-04-18 16:26 UTC] cmb@php.net
[2018-04-18 16:26 UTC] cmb@php.net
-Status: Analyzed
+Status: Closed
[2018-04-18 16:26 UTC] cmb@php.net
[2020-02-07 06:05 UTC] phpdocbot@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 08:00:01 2025 UTC |
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)