Namtip Posted September 6, 2010 Share Posted September 6, 2010 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. Quote Link to comment Share on other sites More sharing options...
Namtip Posted September 6, 2010 Author Share Posted September 6, 2010 Any ideas? I'm stuck. Quote Link to comment Share on other sites More sharing options...
objnoob Posted September 6, 2010 Share Posted September 6, 2010 Show some examples of the browser source of your <img> tags. I have a feeling the src attribute path is causing the errors. Quote Link to comment Share on other sites More sharing options...
Namtip Posted September 6, 2010 Author Share Posted September 6, 2010 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> Quote Link to comment Share on other sites More sharing options...
objnoob Posted September 6, 2010 Share Posted September 6, 2010 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'; Quote Link to comment Share on other sites More sharing options...
Namtip Posted September 6, 2010 Author Share Posted September 6, 2010 Want to swap brains with me? No? Oh, ok. Thanks for the help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.