4images Forum & Community

4images Help / Hilfe => Bug Fixes & Patches => Topic started by: V@no on February 25, 2006, 10:26:48 AM

Title: [1.7 / 1.7.1] PHP v5.1.x and PNG images error
Post by: V@no on February 25, 2006, 10:26:48 AM
Since PHP v5.1 the GD function imagepng() accepts compression argument. The compression argument must be from 0 to 9. 4images is using the compression settings when creating thumbnails or image resizing for jpeg images which can be from 0 to 100. Because of that using imagepng() function will return fatal error
Quote
PHP Fatal error: imagepng() [<a href='function.imagepng'>function.imagepng</a>]: gd-png: fatal libpng error: zlib error in example.php on line 10

The fix is simple:
In includes/image_utils.php find:
Code: [Select]
    $image_handle = "image".$types[$image_info[2]];
Insert below:
Code: [Select]
    if ($image_info[2] == 3) $quality = 9;
Title: Re: [1.7 / 1.7.1] PHP v5.1.x and PNG images error
Post by: Sunny C. on March 16, 2010, 10:00:51 PM
Member Upload work with png fix
ACP Upload dont work with png fix

Image file uploaded: bioshock2_details.png
Error while uploading the thumbnail image: bioshock2_thumbnail.png
bioshock2_details.png: The file has an invalid format (png, image / png)

Image file deleted
Data not written to the database

----

Bild-Datei erfolgreich upgeloadet: bioshock2_details.png
Fehler beim Upload der Thumbnail-Bilddatei: bioshock2_thumbnail.png
bioshock2_details.png: Die Datei hat ein ungültiges Format (png, image/png)

Bild-Datei wieder gelöscht
Daten nicht in die Datenbank geschrieben

(http://s6b.directupload.net/images/100316/vwshh7t5.png)
Title: Re: [1.7 / 1.7.1] PHP v5.1.x and PNG images error
Post by: V@no on March 17, 2010, 12:35:47 AM
FAQ -> How can I add more allowed file extensions? (http://www.4homepages.de/forum/index.php?topic=7277.0)
Title: Re: [1.7 / 1.7.1] PHP v5.1.x and PNG images error
Post by: Sunny C. on March 17, 2010, 12:43:55 AM
Yes i have. But dont work.....
And is a fresh with little modifikation 4images installation
Png is an allowed file extensions!
Title: Re: [1.7 / 1.7.1] PHP v5.1.x and PNG images error
Post by: V@no on March 17, 2010, 01:44:23 AM
and you have image/png  MIME type?
Title: Re: [1.7 / 1.7.1] PHP v5.1.x and PNG images error
Post by: Sunny C. on March 17, 2010, 01:58:11 AM
Yes MIME
(image/png image/x-png)
Template:
Code: [Select]
<!-- Template file for PNG Files -->
<img src="{media_src}" border="1" alt="{image_name}"{width_height} /><br />
upload_definitions.php
$mime_type_match['png'] = array("image/png", "image/x-png");
Full
<?php
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: upload_definitions.php                               *
 *        Copyright: (C) 2002 Jan Sorgalla                                *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.7.6                                                *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (Lizenz.txt) für weitere Informationen.                 *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (Licence.txt) for further information.                              *
 *                                                                        *
 *************************************************************************/
if (!defined('ROOT_PATH')) {
  die("Security violation");
}
//AUTOMATICALLY GENERATED BY MIME.PHP PLUGIN

$mime_type_match['ai'] = array("application/postscript");
$mime_type_match['aif'] = array("audio/x-aiff");
$mime_type_match['aiff'] = array("audio/x-aiff");
$mime_type_match['au'] = array("audio/basic");
$mime_type_match['avi'] = array("video/x-msvideo", "video/avi");
$mime_type_match['bmp'] = array("image/bmp", "image/x-ms-bmp");
$mime_type_match['css'] = array("text/css");
$mime_type_match['csv'] = array("text/comma-separated-values");
$mime_type_match['doc'] = array("application/msword");
$mime_type_match['eps'] = array("application/postscript");
$mime_type_match['fla'] = array("application/octet-stream");
$mime_type_match['gif'] = array("image/gif");
$mime_type_match['gtar'] = array("application/x-gtar");
$mime_type_match['gz'] = array("application/gzip", "application/x-gzip-compressed");
$mime_type_match['jpeg'] = array("image/jpg", "image/jpeg", "image/pjpeg");
$mime_type_match['jpg'] = array("image/jpg", "image/jpeg", "image/pjpeg");
$mime_type_match['js'] = array("text/javascript");
$mime_type_match['mid'] = array("audio/x-midi", "audio/mid", "audio/midi");
$mime_type_match['mov'] = array("video/quicktime");
$mime_type_match['mp3'] = array("audio/mpeg", "audio/x-mpeg", "audio/mp3", "audio/mpg");
$mime_type_match['mpe'] = array("video/mpeg");
$mime_type_match['mpeg'] = array("video/mpeg");
$mime_type_match['mpg'] = array("video/mpeg");
$mime_type_match['pdf'] = array("application/pdf", "application/x-pdf");
$mime_type_match['png'] = array("image/png", "image/x-png");
$mime_type_match['ppt'] = array("application/vnd");
$mime_type_match['ps'] = array("application/postscript");
$mime_type_match['psd'] = array("application/octet-stream");
$mime_type_match['qt'] = array("video/quicktime");
$mime_type_match['ra'] = array("audio/x-pn-realaudio");
$mime_type_match['ram'] = array("audio/x-pn-realaudio");
$mime_type_match['rar'] = array("application/x-rar-compressed");
$mime_type_match['rm'] = array("audio/vnd.rn-realmedia", "application/vnd.rn-realmedia", "video/vnd.rn-realvideo", "application/vnd");
$mime_type_match['rpm'] = array("audio/x-pn-realaudio-plugin");
$mime_type_match['rtf'] = array("text/plain", "text/richtext", "text/rtf");
$mime_type_match['rtx'] = array("text/plain", "text/richtext", "text/rtf");
$mime_type_match['sit'] = array("application/x-stuffit");
$mime_type_match['snd'] = array("audio/basic");
$mime_type_match['swf'] = array("application/x-shockwave-flash");
$mime_type_match['tar'] = array("application/x-tar");
$mime_type_match['tif'] = array("image/tiff", "application/octet-stream");
$mime_type_match['tiff'] = array("image/tiff", "application/octet-stream");
$mime_type_match['txt'] = array("text/plain", "text/richtext", "text/rtf", "text/html");
$mime_type_match['wav'] = array("audio/x-wav");
$mime_type_match['xls'] = array("application/vnd", "application/x-msexcel");
$mime_type_match['zip'] = array("application/zip", "application/x-zip-compressed");
?>
Title: Re: [1.7 / 1.7.1] PHP v5.1.x and PNG images error
Post by: V@no on March 17, 2010, 02:27:02 AM
Oh, that comes from thumbnail, which apparently doesn't use same list of MIME type as images...

Try this, in includes/upload.php find: (wrong!)
    $this->accepted_extensions['media'] = $config['allowed_mediatypes_array'];

Insert below:
    $this->accepted_extensions['thumb'] = $config['allowed_mediatypes_array'];

Title: Re: [1.7 / 1.7.1] PHP v5.1.x and PNG images error
Post by: Sunny C. on March 17, 2010, 08:08:03 AM
Dont work, in Admin Panel comes:

Quote
Image file uploaded: bioshock2_details.png
Error while uploading the thumbnail image: bioshock2_thumbnail.png
bioshock2_details.png: The file has an invalid format (png, image / png)

Image file deleted
Data not written to the database

Please Help me!
Title: Re: [1.7 / 1.7.1] PHP v5.1.x and PNG images error
Post by: V@no on March 18, 2010, 12:50:02 AM
My apology, my suggestion above was absolutely wrong...

In includes/upload.php find:
    foreach ($mime_type_match as $key => $val) {

Insert below:
      if (in_array($key, $this->accepted_extensions['thumb'])) {
        if (is_array($val)) {
          foreach ($val as $key2 => $val2) {
            $this->accepted_mime_types['thumb'][] = $val2;
          }
        }
        else {
          $this->accepted_mime_types['thumb'][] = $val;
        }
      }
Title: Re: [1.7 / 1.7.1] PHP v5.1.x and PNG images error
Post by: Sunny C. on March 18, 2010, 10:58:10 AM
WORKS VERY FINE!
Please write this fix in your first Post!

Thank you V@no, you are my Hero :P

LG