Multiple images output problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
krimson
Forum Newbie
Posts: 1
Joined: Mon Oct 15, 2007 5:34 am

Multiple images output problem

Post by krimson »

Hello everybody,

I'm currently attempting to mask the links of my site's images by outputting them through a php script. Information such as name and date is stored in a mysql database and used to obtain the full path to each image.

I have 2 main files. The files (view.php & thumb.php) are pretty much the same, except that one gets the link for the full-sized image and the other gets the link for the thumb. When accessing either view.php or thumb.php for an individual image, everything works fine. So far, so good.

But I want to include a number of thumbs with links to the full-sized versions in my blog. So i created a function for my active template which allows me to post as many images as i want in a post just by searching for 'post_id' in my database (instead of manually typing multiple a href's and img src's )

Now for the problem: At first, everything looked alright, but after browsing through a couple more pages, i noticed that the thumbs started to disappear, first randomly and then complete. If i wait a couple of minutes, everything starts working again, but not for long.

What could be the source of this apparent random issue? How can I solve this? Any answers would be very appreciated.

Regards,
krimson


Here is the code:

Table's structure:

Code: Select all

#id, name, year, month, day, post_id, rel
thumb.php (it's virtually identical with view.php, except for the ".thumb.jpg" part)

Code: Select all

<?php
include 'db.inc';

  $id = clean($_GET['id'], 4);

  if (empty($id))
     exit;
  if (empty($type))
     $type="med";
  if (!($connection = @ mysql_pconnect($hostName, $username, $password)))
     showerror();

  if (!mysql_select_db($datab, $connection))
     showerror();
        $query = "SELECT year, month, day, name FROM xt_images WHERE id=$id";
        if (!($result = @mysql_query($query,$connection)))
           showerror();  

        $data = @mysql_fetch_array($result);
        $imagedir = "/home/user/public_html/upload/";
        $imagepath = $imagedir . $data["year"] . "/" . $data["month"] . "/" . $data["day"] . "/" . $data["name"] . ".thumb.jpg";

        // {
           // Output the MIME header
           header("Content-Type: image/jpeg");
           // Output the image
           readfile($imagepath);
           exit(0);
        // }

?>
Post function:

Code: Select all

function post_thumbs($post_id, $rel) {
        if (!($connection = mysql_connect($hostName, $username, $password)))
                 showerror();

        if (!mysql_select_db($datab, $connection))
                 showerror();

        $query = 'SELECT id, rel FROM xt_images WHERE post_id='. $post_id .' AND rel="'. $rel .'"';
        if (!($result = mysql_query($query,$connection)))
                 showerror();
        print('<center>');
        while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
                 print('<a href="http://img.mydomain.com/view.php?id='. $line['id'] . '" rel="lightbox['. $rel .']">');
                 print('<img src="http://img.mydomain.com/thumb.php?id='. $line['id'] .'" />');
                 print('</a> ');
        }
        print('</center>');
}
Last edited by krimson on Sun Oct 21, 2007 11:33 am, edited 1 time in total.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

That's just bizarre.. if the problem is randomly intermittent it will be pure hell to track down!
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Checked the error log?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I'd get rid of error suppression to start. I would then look at the actual output of the page to make sure that everytime something in the request changes the appropriate information is making it to those scripts.
Post Reply