rdburbridgesr Posted February 16, 2015 Share Posted February 16, 2015 Everything with one exception is working fine in showing the images. When I click on any of the images, it will only show the unavailable image. I've renamed the unvailable.png to the extension of jpg. It shows the unavailable.jpg but nothing else. Clicking on tree.jpg shows unavailable.jpg - looking at the page it says tree.jpg and the source code shows tree.jpg. Any thoughts? Link to comment Share on other sites More sharing options...
Larry Posted February 18, 2015 Share Posted February 18, 2015 Normally this is a path problem, either in the URL or on the filesystem. What is the URL (in the browser) that's showing the unavailable image? Link to comment Share on other sites More sharing options...
rdburbridgesr Posted February 19, 2015 Author Share Posted February 19, 2015 Hi Larry, From the View Source using Firefox, it only shows the image name, no path is showing. Link to comment Share on other sites More sharing options...
rdburbridgesr Posted February 20, 2015 Author Share Posted February 20, 2015 This is becoming very confusing. Now I have a pop up with the correct dimensions matching the images dimensions, however not even the unavilable.png file shows. Using the properties on what I am seeing in the pop up, first the background colour is all black with the words: The image "http://rdburbridge.org/show_image.php?image=unavailable.png"cannot be displayed because it contains errors. Before clicking the image names to get the pop up, those images do show in the listing properly. Just when I click on each one, the popup adjusts for each images dimensions with this error here: Looking at the View Image Info from that popup, there are two lines: 1) chrome://global/skin/media/imagedoc-darknoise.png 2) http://rdburbridge.org/show_image.php?image=unavailable.png I do not use Chrome. I have checked this in Firefox my primary and MSIE. The unavailable.png is located at http://rdburbridge.org/images/unavailable.pngwhere the other images I have uploaded using the upload.php are outside the domain: ../uploads Very confusing but I have patience and I just know it's going to be educational for me. Link to comment Share on other sites More sharing options...
Larry Posted February 20, 2015 Share Posted February 20, 2015 Okay, it's really just a matter of either paths or permissions being wrong. Can you post your images.php and show_image.php files? Link to comment Share on other sites More sharing options...
rdburbridgesr Posted February 20, 2015 Author Share Posted February 20, 2015 Absolutely, thank you sir images.php: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-transitional.dtd"><html xmlns="http://www.w3.org/TR/xhtml"xml:lang="en" lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Images</title><script type="text/javascript" charset="utf-8" src="js/function.js"></script></head><body><p>Click on an image to view it in a separate window.</p> <ul> <?php # Script 11.4 - images.php// This script lists the images in the uploads directory. $dir = '../uploads/'; // Define the directory to view. $files = scandir($dir); // Read all the images into an array.// Display each image caption as a link to the JavaScript function: foreach ($files as $image) { if (substr($image, 0, 1) != '.') { // Ignore anything starting with a period.// Get the image's size in pixels: $image_size = getimagesize("$dir/$image");// Make the image's name URL-safe: $image_name = urlencode($image);// Print the information: echo "<li><a href=\"javascript:create_window('$image_name', $image_size[0], $image_size[1])\">$image</a></li>\n";} // End of the IF.} // End of the foreach loop.?></ul></body> show_image.php: <?php # Script 11.5 - show_image.php// This page displays an image.$name = FALSE; // Flag variable:// Check for an image name in the URL:if (isset($GET['image'])) {// Make sure it has an image's extension:$ext = strtolower ( substr ($_GET['image'], -4));if (($ext == '.jpg') OR ($ext == 'jpeg') OR ($ext == '.png')) {// Full image path:$image = "../uploads/{$_GET['image']}";// Check that the image exists and is a file:if (file_exists ($image) && (is_file($image))) {// Set the name as this image:$name = $_GET['image'];} // End of file_exists( ) IF.} // End of $ext IF.} // End of isset($_GET['image']) IF.// If there was a problem, use the default image:if (!$name) {$image = './images/unavailable.png';$name = 'unavailable.png';}// Get the image information:$info = getimagesize($image);$fs = filesize($image);// Send the content information:header ("Content-Type: {$info['mime']}\n");header ("Content-Disposition: inline; filename=\"$name\"\n");header ("Content-Length: $fs\n");// Send the file:readfile ($image); Link to comment Share on other sites More sharing options...
Larry Posted February 23, 2015 Share Posted February 23, 2015 Hmmm...not seeing anything obviously wrong here. It could be a permissions issue. You'll need to do some annoying debugging to figure out the issue. Basically you'll want to do something like this: <?php # Script 11.5 - show_image.php // This page displays an image. $name = FALSE; // Flag variable: // Check for an image name in the URL: if (isset($GET['image'])) { echo '<p>GET[image] is set</p>'; // Make sure it has an image's extension: $ext = strtolower ( substr ($_GET['image'], -4)); echo "<p>\$ext is $ext</p>"; if (($ext == '.jpg') OR ($ext == 'jpeg') OR ($ext == '.png')) { echo '<p>extension is fine</p>'; // Full image path: $image = "../uploads/{$_GET['image']}"; echo "<p>\$image is $image</p>"; // Check that the image exists and is a file: if (file_exists ($image) && (is_file($image))) { echo '<p>Image exists and is a file</p>'; Do that throughout your script and run it to see what is and is not happening. You'll need to comment-out the header and read file lines, though (or else the browser won't show the text). Link to comment Share on other sites More sharing options...
rdburbridgesr Posted February 23, 2015 Author Share Posted February 23, 2015 It looks strange, but the isset line towards the top - the $GET I already replaced with $_GET and that didn't do anything. I hadn't thought of echoing those lines out to screen, I'll try that and let you know. Just as a side note, in Chapter 18 I had to change the name over from require MYSQL to get it to work. I added a 1 and it worked fine. MYSQL1. Link to comment Share on other sites More sharing options...
rdburbridgesr Posted February 24, 2015 Author Share Posted February 24, 2015 Nothing worked, so here's what I came up with and this does work for the most part. A rewrite (copy paste put together actually): I'm not able to get the windows to adjust because I don't fully understand javascript. So I'm off to the bookstore to get a copy of your javascript manual. ################################################# function popup(mylink, windowname){if (!window.focus)return true;var href;if (typeof(mylink) == 'string') href=mylink;else href=mylink.href; david=window.open(href, 'windowname', 'width=500, height=500, left=400, top=150,'); if (window.focus) {david.focus()} if (!david.closed) {david.focus()}return false; ######################################################### Link to comment Share on other sites More sharing options...
rdburbridgesr Posted February 24, 2015 Author Share Posted February 24, 2015 ################################## I'm sorry, I should have mentioned. That is from the function.js file and also I used my ftp program to get the url of the pictures and it comes back as ftp://ftp.rdburbridge.org/uploads/richard-01.jpg My directory structure starts at public_html. If I go one above that to keep things private as you suggest, then the url completely changes to what I've shown above. Also if I put that url in my browser, of course it will give a popup asking for username/password for the ftp abilities. So I've put the uploads directory in my public_html folder as normal and with the different function as indicated in the last post, it works fine without the $image_size[0] and [1] ability. I have learned so very much from your books and I am very happy and quite proud of myself that I've been able to come this far. All these years I've put websites together but not really knowing what I was doing. I had to purchase other's programs in cgi/perl, javascript and such to accomplish things, but never really knew what all that was doing. I tried to learn this stuff over 15 years ago, but it was very difficult so I just gave up. You - Larry Ullman, have given me a reason to hope and have helped me to become more proud of what I am doing now. Not to mention that I know that the code I am using doesn't have any spyware in it in case those programs I was buying happened to have coding in it so they could watch me. Thank you Mr. Ullman - your efforts have paid off for at least one of us out here. Richard Burbridge Link to comment Share on other sites More sharing options...
Larry Posted February 25, 2015 Share Posted February 25, 2015 Thanks for the very, very nice words, Richard. I'm glad my work has been helpful to you, and thanks for saying so. Do let me know if you have any further questions or problems in the future. Link to comment Share on other sites More sharing options...
Recommended Posts