Page 1 of 1

Multiple images output problem

Posted: Mon Oct 15, 2007 5:48 am
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>');
}

Posted: Mon Oct 15, 2007 2:35 pm
by Kieran Huggins
That's just bizarre.. if the problem is randomly intermittent it will be pure hell to track down!

Posted: Mon Oct 15, 2007 7:40 pm
by Benjamin
Checked the error log?

Posted: Mon Oct 15, 2007 10:41 pm
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.