?
Solved

Simple display image Code won't work in PHP5

Posted on 2007-10-06
11
Medium Priority
?
356 Views
Last Modified: 2011-09-20
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
Comment
Question by:jags2ooo
  • 7
  • 4
11 Comments
 
LVL 20

Expert Comment

by:Gawai
ID: 20027756
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
 
LVL 20

Expert Comment

by:Gawai
ID: 20027761
i guess it will not work. coz the variable 'what' is repeated
0
 

Author Comment

by:jags2ooo
ID: 20027790
Doesn't work gawai :(
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:Gawai
ID: 20027799
did you try changing the variable name ?
0
 

Author Comment

by:jags2ooo
ID: 20027936
Yes i tried doesn't work i had changed it to scan
0
 
LVL 20

Expert Comment

by:Gawai
ID: 20027959
make sure images and the directory are exist in server
0
 

Author Comment

by:jags2ooo
ID: 20027967
Yes of course they are all there. If i run a  scandir + print_r the images in the directory  are all listed.  
0
 
LVL 20

Accepted Solution

by:
Gawai earned 2000 total points
ID: 20027985
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
 
LVL 20

Expert Comment

by:Gawai
ID: 20027994
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
 

Author Comment

by:jags2ooo
ID: 20028196
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
 
LVL 20

Expert Comment

by:Gawai
ID: 20030636
u r most welcome my dear :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month16 days, 23 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question