ID:               34829
 User updated by:  kylnas at tiscali dot it
 Reported By:      kylnas at tiscali dot it
-Status:           Feedback
+Status:           Open
 Bug Type:         Filesystem function related
 Operating System: Linux
 PHP Version:      4.4.0
 New Comment:

This is the script I use to create thumb (I'm sorry but i can't do
better than this to permit you to recreate the error) :
<?php

$use_resampling = true;
$use_truecolor = true;
$gif_as_jpeg = false;
$tn_server_cache = true;
subdirectory and is writeable!
$tn_path = 'thumbnails/';
$tn_browser_cache = true; // The default is true
$use404 = true; // The default is true
$r = 255; // Red color value (0-255)
$g = 255; // Green color value (0-255)
$b = 255; // Blue color value (0-255)
$allow_larger = false; // The default is false.
$show_original = true; // The default is true.

function reverse_strrchr($haystack, $needle)
{
        return strrpos($haystack, $needle) ? substr($haystack, 0,
strrpos($haystack, $needle) +1 ) : false;
} 

function modify_tn_path($file)
{
        global $tn_path;

        if ($tn_path=='') return $file;
        else {
                // append the thumbnail-path to the path
                $pathSep = strstr(PHP_OS, "WIN") ? "\\" : "/";;
                $path = reverse_strrchr($file,$pathSep);
                if ($path===false) return $tn_path . $file;
                else return str_replace($path,$path . $tn_path,$file);
        }
}

function http_headers($file='')
{
        global $use404, $tn_browser_cache;
        
        if (isset($_SERVER["SERVER_PROTOCOL"]) && $_SERVER["SERVER_PROTOCOL"]
== "HTTP/1.1") 
                $httpProtocol = "HTTP/1.1";
        else
                $httpProtocol = "HTTP/1.0";
        
        if (file_exists($file))
        {

                if (isset ($_SERVER["HTTP_CACHE_CONTROL"])) {
                        $tn_browser_cache = 
strtolower($_SERVER["HTTP_CACHE_CONTROL"]) ==
"no-cache" ? false : $tn_browser_cache ;
                }
                
                $lastModified = filemtime($file);
                $lastModifiedGMT = $lastModified - date('Z');
                $lastModifiedHttpFormat = gmstrftime("%a, %d %b %Y %T %Z",
$lastModified);
                $eTag = '"1fa44b7-' . dechex(filesize($file)) . "-" .
dechex($lastModifiedGMT) . '"';
        
                if ($tn_browser_cache){
                
                        $lastModifiedFromHttp = "xxx";
                        if (isset ($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
                                $lastModifiedFromHttp = 
($_SERVER["HTTP_IF_MODIFIED_SINCE"] === "")
? "xxx" : $_SERVER["HTTP_IF_MODIFIED_SINCE"] ;
                        }
                        
                        $foundETag = "";
                        if (isset ($_SERVER["HTTP_IF_NONE_MATCH"])) {
                                $foundETag = 
stripslashes($_SERVER["HTTP_IF_NONE_MATCH"]);
                        }
                        
                        if ($lastModifiedFromHttp == $lastModifiedHttpFormat) {
                                $sameLastModified = true;
                        }
                        elseif 
(strpos($lastModifiedFromHttp,$lastModifiedHttpFormat) !==
false){
                                $sameLastModified = true;
                        }
                        else {
                                $sameLastModified = false;
                        }
                        
                        if (($eTag == $foundETag) && $sameLastModified){
Modification Time (e.g. with Firefox)
                                $is304 = true;
                        }
                        else
Last Modification Time is unchanged (e.g. with IE 6.0)
                                $is304 = (($foundETag == "") && 
$sameLastModified);

                        if ($is304)
                        {
                                if ($lastModifiedGMT > 946080000) {
                                        header("ETag: " . $eTag);
                                }
                                header("Status: 304 Not Modified");
                                header($httpProtocol . " 304 Not Modified");
                                header("Connection: close");
                                exit();
                        }
                }

                header('Pragma: ');
                header('Expires: ');
                if ($tn_browser_cache){
                        if ($lastModifiedGMT > 946080000) {       
                                header('ETag: ' . $eTag);
                        }
                        header('Last-Modified: ' . $lastModifiedHttpFormat);
                        header('Cache-Control: private');
                }
                else {
                        header('Cache-Control: no-cache');
                }

        }
        else
        {
                if ($use404)
                {
                        header("TEST404: TEST404");
                        header("Status: 404 Not Found");
                        header($httpProtocol . " 404 Not Found");
                        exit();
                }
                else
                {
(non-cacheable by the browser)                  
                        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");       
                
                        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " 
GMT");
                        header("Cache-Control: no-store, no-cache, 
must-revalidate");
                        header("Cache-Control: post-check=0, pre-check=0", 
false);
                        header("Pragma: no-cache");                     
header('Content-type: image/jpeg');
                        $src = imagecreate($_GET['w'], $_GET['h']);             
                                                                $bgc =
imagecolorallocate($src, 255, 255, 255);
                        $tc  = imagecolorallocate($src, 0, 0, 0);
                        imagefilledrectangle($src, 0, 0, $_GET['w'], 
$_GET['h'], $bgc);
                        imagestring($src, 1, 5, 5, 'Error', $tc);
                        imagejpeg($src, '', 100);
                        imagedestroy($src);
                        exit();
                }
        }
}


$image = @getimagesize($_GET['img']);

if (empty($image) || empty($_GET['w']) || empty($_GET['h']) ||
(empty($allow_larger) && ($_GET['w'] > $image[0] || $_GET['h'] >
$image[1])))
{
        if (empty($image) || empty($show_original))
        {
                http_headers();
        }
        else
        {
                $_GET['w'] = $image[0];
                $_GET['h'] = $image[1];
        }
}

if ($image[2] == 2 || ($image[2] == 1 && $gif_as_jpeg))
{
        header('Content-type: image/jpeg');
        if ($tn_server_cache) $filename = modify_tn_path($_GET['img']
.'.thumb_'.$_GET['w'].'x'.$_GET['h'].'.jpg');
}
elseif ($image[2] == 1 && function_exists('imagegif'))
{
        header('Content-type: image/gif');
        if ($tn_server_cache) $filename = modify_tn_path($_GET['img']
.'.thumb_'.$_GET['w'].'x'.$_GET['h'].'.gif');
}
elseif ($image[2] == 3 || $image[2] == 1)
{
        header('Content-type: image/png');
        if ($tn_server_cache) $filename = modify_tn_path($_GET['img']
.'.thumb_'.$_GET['w'].'x'.$_GET['h'].'.png');
}

if (file_exists($filename) && $tn_server_cache && filemtime($filename)
> filemtime($_GET['img']))
{
        http_headers($filename);
        
        if ($image[2] == 2 || ($image[2] == 1 && $gif_as_jpeg))
        {
                $src = imagecreatefromjpeg($filename);
                imagejpeg($src, '', 100);
        }
        elseif ($image[2] == 1 && function_exists('imagegif'))
        {
                $src = imagecreatefromgif($filename);
                imagegif($src);
        }
        elseif ($image[2] == 3 || $image[2] == 1)
        {
                $src = imagecreatefrompng($filename);
                imagepng($src);
        }
        else
        {
                http_headers();
        }
}
else
{
        if (function_exists('imagecreatetruecolor') && $use_truecolor &&
($image[2] == 2 || $image[2] == 3))
        {
                $tmp_img = imagecreatetruecolor($_GET['w'],$_GET['h']);
        }
        else
        {
                $tmp_img = imagecreate($_GET['w'],$_GET['h']);
        }

        $th_bg_color = imagecolorallocate($tmp_img, $r, $g, $b);

        imagefill($tmp_img, 0, 0, $th_bg_color);
        imagecolortransparent($tmp_img, $th_bg_color);

        if ($image[2] == 2 && function_exists('imagecreatefromjpeg'))
        {
                $src = imagecreatefromjpeg($_GET['img']);
        }
        elseif ($image[2] == 1 && function_exists('imagecreatefromgif'))
        {
                $src = imagecreatefromgif($_GET['img']);
        }
        elseif (($image[2] == 3 || $image[2] == 1) &&
function_exists('imagecreatefrompng'))
        {
                $src = imagecreatefrompng($_GET['img']);
        }
        else
        {
                http_headers();
        }

        if (function_exists('imagecopyresampled') && $use_resampling)
        {
                imagecopyresampled($tmp_img, $src, 0, 0, 0, 0, $_GET['w'],
$_GET['h'], $image[0], $image[1]);
        }
        else
        {
                imagecopyresized($tmp_img, $src, 0, 0, 0, 0, $_GET['w'], 
$_GET['h'],
$image[0], $image[1]);
        }

        if ($image[2] == 2 || ($image[2] == 1 && $gif_as_jpeg))
        {
                if ($tn_server_cache)
                {
                        $thumbnail =
modify_tn_path($_GET['img'].'.thumb_'.$_GET['w'].'x'.$_GET['h'].'.jpg');
                        imagejpeg($tmp_img,$thumbnail, 100);
                        http_headers($thumbnail);
                }
                else
                {
                        http_headers($_GET['img']);
                }
                imagejpeg($tmp_img, '', 100);
        }
        elseif ($image[2] == 1 && function_exists('imagegif'))
        {
                if ($tn_server_cache)
                {
                        $thumbnail =
modify_tn_path($_GET['img'].'.thumb_'.$_GET['w'].'x'.$_GET['h'].'.gif');
                        imagegif($tmp_img,$thumbnail);
                        http_headers($thumbnail);
                }
                else
                {
                        http_headers($_GET['img']);
                }
                imagegif($tmp_img);
        }
        elseif ($image[2] == 3 || $image[2] == 1)
        {
                if ($tn_server_cache)
                {
                        $thumbnail =
modify_tn_path($_GET['img'].'.thumb_'.$_GET['w'].'x'.$_GET['h'].'.png');
                        imagepng($tmp_img,$thumbnail);
                        http_headers($thumbnail);
                }
                else
                {
                        http_headers($_GET['img']);
                }
                imagepng($tmp_img);
        }
        else
        {
                http_headers();
        }

        imagedestroy($src);
        imagedestroy($tmp_img);
}
?>


Previous Comments:
------------------------------------------------------------------------

[2005-10-12 22:25:58] [EMAIL PROTECTED]

"A reproduce script" means I need a script that I can copy/paste and
reproduce the problem. Probably, with some additional actions (like
creating a certain file etc.).

How do you suppose I should reproduce the problem with the script
you've given? Obviously I don't have all your files here.

------------------------------------------------------------------------

[2005-10-12 22:19:53] kylnas at tiscali dot it

This is the code:
<?php
  $filename =
'../images/products/thumbnails/101D0-86_jpg_thumb_75x75.jpg';
  echo 'File does exist but it is not found: ' . $filename . '<br />';
  echo 'If you copy the destination in a browser the file is visible<br
/>';
        if (file_exists($filename))
    echo 'YES<br />';
  else
    echo 'NO<br /><br />';

  $filename1 = '../images/products/thumbnails/tmp_gif';
  echo 'File (in the same directory)) does exist and it is found: ' .
$filename1 . '<br />';
        if (file_exists('../images/products/thumbnails/tmp.gif'))
    echo 'YES<br />';
  else
    echo 'NO<br />';
?>

This is the online link:
http://81.174.30.88/tmp/tmp.php

------------------------------------------------------------------------

[2005-10-11 16:11:07] [EMAIL PROTECTED]

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.



------------------------------------------------------------------------

[2005-10-11 16:09:31] kylnas at tiscali dot it

Description:
------------
PHP 4.3.11
file_exists() doesn't works for some file (created by gd libray),
instead if i create manually a file in the SAME directory the function
works.

Reproduce code:
---------------
$file = 'images/products/thumbnails/11940-77_jpg_thumb_80x68.jpg';      if
(file_exists($file))
 echo 'yes';
else
 echo 'no';

Expected result:
----------------
YES.

The file does exist.

Actual result:
--------------
NO. If I create a file in the same directory (like "tmp.gif") and I use
the same function i get a "Yes" result.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=34829&edit=1

Reply via email to