• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

Simple display image Code won't work in PHP5

This script works fine in php4 but when i put it on my Main server which is php5 it doesn't work. IS there any reason why it wouldn't work in php5?
I attempted to remove  the c_scandir function and use scandir instead for php5 but it still fails.


Example: working (php4) -   http://bleach-network.com/manga-reader/image.php?id=1&what=1
example2: not working (php5)  -   http://bleachnet.mine.nu/Downloads/manga-reader/image.php?id=1&what=1
PHP5 php.ini file   :::   http://bleachnet.mine.nu/Downloads/php.txt


<?php
// Custom scandir function
function c_scandir($dir)
{ if (function_exists('scandir'))
{
 return scandir($dir);
 }
 $fileps = array();
if ($handle = opendir($dir)) {
 while (false !== ($filep = readdir($handle))) {
$fileps[] = $filep;

      }
closedir($handle);
 }

   return $fileps;

}

$komiks = (int) $_GET['id'];
if ($komiks > 0) {
      $what = (int) $_GET['what'];
      if ($what>0) {
            $nrkat = 0;
            $katalog = c_scandir('.');
            foreach ($katalog as $file) {
                  if ((filetype($file)=='dir')&&($file!='.')&&($file!='..')) {
                        $nrkat++;
                        if ($nrkat == $komiks) {
                              $komi = c_scandir($file);
                              $nrko = 0;
                              foreach ($komi as $file2) {
                                    if ((filetype($file.'/'.$file2)=='file')&&($file2!='.')&&($file2!='..')) {
                                          $nrko++;
                                          if ($nrko==$what) {
                                                //ok, to jest ten plik, wyswietlamy go.
                                                $img = null;
                                                $img = @imagecreatefromgif($file.'/'.$file2);
                                                if (!$img) $img = @imagecreatefromjpeg($file.'/'.$file2);
                                                if (!$img) $img = @imagecreatefrompng($file.'/'.$file2);
                                                header("Content-type: image/jpeg");
                                                imagejpeg($img);
                                          }
                                    }
                              }

                        }
                  }
            }
      }      
}
?>
0
jags2ooo
Asked:
jags2ooo
  • 7
  • 4
1 Solution
 
GawaiCommented:
replace
$komiks = (int) $_GET['id'];
if ($komiks > 0) {
      $what = (int) $_GET['what'];

with
$komiks = (int) $id;
if ($komiks > 0) {
      $what = (int) $what;

and see wat happen
0
 
GawaiCommented:
i guess it will not work. coz the variable 'what' is repeated
0
 
jags2oooAuthor Commented:
Doesn't work gawai :(
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
GawaiCommented:
did you try changing the variable name ?
0
 
jags2oooAuthor Commented:
Yes i tried doesn't work i had changed it to scan
0
 
GawaiCommented:
make sure images and the directory are exist in server
0
 
jags2oooAuthor Commented:
Yes of course they are all there. If i run a  scandir + print_r the images in the directory  are all listed.  
0
 
GawaiCommented:
just for testing purpose run this code to make sure GD library installed or not

<?php
header("Content-type: image/jpeg");
$im = imagecreatefromjpeg("file.jpeg");
imagejpeg($im);
imagedestroy($im);
?>
0
 
GawaiCommented:
or this one

function LoadJpeg($imgname)
{
    $im = @imagecreatefromjpeg($imgname); /* Attempt to open */
    if (!$im) { /* See if it failed */
        $im  = imagecreatetruecolor(150, 30); /* Create a black image */
        $bgc = imagecolorallocate($im, 255, 255, 255);
        $tc  = imagecolorallocate($im, 0, 0, 0);
        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
        /* Output an errmsg */
        imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
    }
    return $im;
}
header("Content-Type: image/jpeg");
$img = LoadJpeg("12.jpg");
imagejpeg($img);
0
 
jags2oooAuthor Commented:
gawai Thank you Very much my friend! AMAZING i spent so many hour  modifying code trying to figure out what was wrong >< THANK YOU!
0
 
GawaiCommented:
u r most welcome my dear :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now