Jump to content

Script doesn't upload thumbnail and produces an error when clicking the link.


Namtip

Recommended Posts

Goal: To have a gallery that downloads images from the folder I previously uploaded to in a previous script.

 

Bug: When I load the page the thumbnail comes up as broken and when I click on the thumbnail to get the bigger picture it comes up with the following error message:

 

"Firefox doesn't know how to open this address, because the protocol © isn't associated with any program."

 

<?php
include 'db.inc.php';
//connect to MySQL
$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or 
    die ('Unable to connect. Check your connection parameters.');
mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db));

//change this path to match your images directory
$dir ='C:/x/xampp/htdocs/images';

//change this path to match your thumbnail directory
$thumbdir = $dir . '/thumbs';
?>
<html>
<head>
  <title>Welcome to our Photo Gallery</title>
  <style type="text/css">
   th { background-color: #999;}
   .odd_row { background-color: #EEE; }
   .even_row { background-color: #FFF; }
  </style>
</head>
<body>
  <p>Click on any image to see it full sized.</p>
  <table style="width:100%;">
   <tr>
    <th>Image</th>
    <th>Caption</th>
    <th>Uploaded By</th>
    <th>Date Uploaded</th>
   </tr>
<?php
//get the thumbs
$result = mysql_query('SELECT * FROM images') or die(mysql_error());

$odd = true;
while ($rows = mysql_fetch_array($result)) {
    echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">';
    $odd = !$odd; 
    extract($rows);
    echo '<td><a href="' . $dir . '/' . $image_id . '.jpg">';
    echo '<img src="' . $thumbdir . '/' . $image_id . '.jpg">';
    echo '</a></td>';
    echo '<td>' . $image_caption . '</td>';
    echo '<td>' . $image_username . '</td>';
    echo '<td>' . $image_date . '</td>';
    echo '</tr>';
}
?>
  </table>
</body>
</html>

 

Any help appreciated.

This is the code the browser gives me when I right click view source. Is that what you mean?

<html>
<head>
  <title>Welcome to our Photo Gallery</title>
  <style type="text/css">
   th { background-color: #999;}
   .odd_row { background-color: #EEE; }
   .even_row { background-color: #FFF; }
  </style>
</head>
<body>
  <p>Click on any image to see it full sized.</p>
  <table style="width:100%;">

   <tr>
    <th>Image</th>
    <th>Caption</th>
    <th>Uploaded By</th>
    <th>Date Uploaded</th>
   </tr>
<tr class="odd_row"><td><a href="C:/x/xampp/htdocs/images/1.jpg"><img src="C:/x/xampp/htdocs/images/thumbs/1.jpg"></a></td><td>yes</td><td>Hot</td><td>2010-09-06</td></tr>  </table>

</body>
</html>

The problem is path. The path should be '/images/thumbs/1.jpg';  The initial / maps to your WWW root directory which is C:/x/xampp/htdocs/

 

So change your code to:

 

$dir ='/images';
$thumbdir = $dir . '/thumbs';

 

if you wanted to use a direct link something like this would work:

$dir ='http://localhost/images';
$thumbdir = $dir . '/thumbs';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.