Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hello Larry and everyone else, thank you for replying so quickly yesterday.

I spent hours looking for the error and just could not see it, once it was pointed out it was so obvious.

 

Ive been at it again, up all night till 8am this morning, i can,t get the window to load in script 10.4

The html form works, the links are there, the images are in the folder, sharing is on.

Ive just spent the last hour looking and still can not see an error, please could someone else have a look, thank you.. Regards Chris

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Images</title>

<script language="javascript">

<!-- // Hide from old browsers

function create_window(image, width, height) { // Popup window function

width = width + 10; //Add pixels

height = height + 10;

//If the window is already open

// resize it to the new dimensions

if (window.popup &&

!window.popup.closed) {

window.popup.resizeTo(width, height);

}

// Set the window properties

var specs = "location=no,

scrollbars=no, menubars=no,

toolbars=no, resizeable=yes, left=0,

top=0, width=" + width + ",

height=" + height;

 

var url = "show_image.php?image=" + image;

 

popup = window.open(url, "ImageWindow", specs);

popup.focus();

}// End of function

 

--></script>

</head>

 

<body>

<p>Click on an image to view it in a seperate window</p>

<table align="center" cellspacing="5" cellpadding="5" border="1" >

<tr>

<td align="center"><b>Image Name</b></td>

<td align="center"><b>Image Size</b></td>

</tr>

<?php # Script 10.4 - image.php

$dir = 'C:/wamp/uploads';

 

$files = scandir($dir);

 

foreach ($files as $image) {

 

if (substr($image,0,1) != '.'){

 

$image_size = getimagesize("$dir/$image");

 

$file_size = round( (filesize("$dir/$image")) / 1024) . "kb";

 

$image = urlencode($image);

 

echo "\t<tr>

 

\t\t<td><a href=\"javascript:create_window

('$image', $image_size[0], $image_size[1])\">$image</a></td>

 

\t\t<td>$file_size</td>

 

\t</tr>\n";

}// End of the IF

} // End of the for each loop ?>

</table>

</body>

</html>

 

 

 

 

 

 

 

 

 

Here is the view source page:

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Images</title>

<script language="javascript">

<!-- // Hide from old browsers

function create_window(image, width, height) { // Popup window function

width = width + 10; //Add pixels

height = height + 10;

//If the window is already open

// resize it to the new dimensions

if (window.popup &&

!window.popup.closed) {

window.popup.resizeTo(width, height);

}

// Set the window properties

var specs = "location=no,

scrollbars=no, menubars=no,

toolbars=no, resizeable=yes, left=0,

top=0, width=" + width + ",

height=" + height;

 

var url = "show_image.php?image=" + image;

 

popup = window.open(url, "ImageWindow", specs);

popup.focus();

}// End of function

 

--></script>

</head>

 

<body>

<p>Click on an image to view it in a seperate window</p>

<table align="center" cellspacing="5" cellpadding="5" border="1" >

<tr>

<td align="center"><b>Image Name</b></td>

 

<td align="center"><b>Image Size</b></td>

</tr>

<tr>

 

<td><a href="javascript:create_window

('Calif-cut-out.jpg', 3072, 2048)">Calif-cut-out.jpg</a></td>

 

<td>394kb</td>

 

</tr>

<tr>

 

<td><a href="javascript:create_window

('Fruit.jpg', 487, 414)">Fruit.jpg</a></td>

 

<td>137kb</td>

 

</tr>

<tr>

 

<td><a href="javascript:create_window

('p900+001.jpg', 288, 352)">p900+001.jpg</a></td>

 

<td>24kb</td>

 

</tr>

<tr>

 

<td><a href="javascript:create_window

('p900+007.jpg', 640, 480)">p900+007.jpg</a></td>

 

<td>48kb</td>

 

</tr>

 

<tr>

 

<td><a href="javascript:create_window

('p900+011.jpg', 288, 352)">p900+011.jpg</a></td>

 

<td>30kb</td>

 

</tr>

</table>

</body>

</html>

Link to comment
Share on other sites

chris, I'll try and lend a hand, but I am honestly confused about a couple of things. For one, all we have to go on is the following:

 

"i can,t get the window to load in script 10.4

The html form works, the links are there, the images are in the folder, sharing is on."

 

Honestly, this isn't very clear. When you say that the window won't load, do you mean the pop-up window? Also, you say the "HTML form", but there is no form in your code. Do you mean just the HTML page?

 

Anyway, I'm going to venture a guess at the problem: Probably, the images folder cannot be accessed for one reason or another. I'm not sure about WAMP, but I use XAMPP, and in that, all files/folders that are accessed from localhost must be in the htdocs folder, so I'm thinking that your virtual server (or whatever it is that you're testing this on), cannot access the images.

 

Are there any errors that are output when you click on a link, etc.? If you're using a browser like Google Chrome, you can load up a JavaScript debugger, and see if there are any errors being generated on the JS side of things.

 

Again, it's hard to diagnose the error without more information.

 

Whenever I have an issue with PHP, I generally start echoing things left and right. I highly recommend echoing a lot of stuff out to the screen, and making sure that everything is as you have intended. If everything is as it should be, then there is probably an issue with the environment you have set up (e.g., permissions are not set properly, a folder isn't where it should be, etc.).

 

Anyway, try some stuff out, and please report back. Thanks.

 

Edit: If the problem was a syntax error, then some sort of error would be output to the screen, but since just nothing is being displayed, then there is some sort of runtime error.

  • Upvote 1
Link to comment
Share on other sites

Hi, there are no errors coming back.

I should have put html page, rather than html form.

The html page loads with the table. The links are there to the images and the links change color when you select them, it is just the popup that does not do anything.

No errors are returned.

I have pasted the source too, so you can see the links and table are there.

Link to comment
Share on other sites

I now have the popup window working now, it was the javascript from var specs = "Location=no,

I put this piece of script in a line rather than a block as i first did and it works(with the help of firebug)

 

I still do not have the images though. It say's:

 

 

Not Found

 

The requested URL /php6/show_image.php was not found on this server

Link to comment
Share on other sites

Well, I think that's your answer right there. You either don't have the show_image.php file, or it's in the wrong folder.

 

It's been a while since I went through this book, so I don't recall well, but I checked the index of the book, and there is a show_image.php script starting on page 566. Perhaps if you wrote that script out and placed it in the appropriate folder.

 

I find it odd though, as the show_image.php script is in a completely different section, and no real reference is ever made to that script in 10.4. Hmmm...that is odd.

 

I'm thinking if you write the script on page 566, and modify it as necessary, it should work. Please let us know if that works or not.

  • Upvote 1
Link to comment
Share on other sites

Hi, i don't have a folder called show_image.php

 

I copied the first script- 10.3 which was called upload image.php

which created a page to browse and upload images into a folder called uploads, which is kept outside of the www directory in wamp.

 

I then did script 10.4 which is called images.php

which uses java and php to load images in a window.

 

the first page with the table for the images works and i can select an image which has a link in the file uploads, yet when the window opens and resizes as it shouid, i get the message php6/show_image.php not found on this server

 

part of thhe java in sript 10.4 says //set the url var url = "show_image.php?image=" + image;

 

The part of the php that says $dir = '../uploads';//Define the directory to view I have changed to $dir = 'C:/wamp/uploads'; and that works as i get the links to the images when the images.php is loaded

Only when i select an image to view it loads a seperate window saying php6/show_images.php not found on this server

 

Im using dremweaver as an editer and have called a new site php6 for the purpose of all the scripts in this book

 

I don't understand what the var url = "show_image.php?image=" + image; refers to?

 

Here is my script again which is actually larry's script copied and pasted to my page and then the $dir = '../uploads'; changed

 

I found the original issue i had with the java script window not opening was because the script in the book was different to the script i copied from the website

If the part that says "location=no, scrollbars=no, menubars=no, toolbars=no, resizable=yes, left=0, top=0, width=" + width + ", height=" + height;

If it is not all on one line and is written as in the book(over four lines) it does not work and firebug brings up an illegal error after ""location=no When i copied and pasted the scipt from the website, it worked, although it is exactly the same, just on one line not four.

 

Please could someone look at my script and tell me why i am getting php6/show_image.php not found on this server thanks

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

<title>Images</title>

<script language="JavaScript">

<!-- // Hide from old browsers.

 

// Make a pop-up window function:

function create_window (image, width, height) {

 

// Add some pixels to the width and height:

width = width + 10;

height = height + 10;

 

// If the window is already open,

// resize it to the new dimensions:

if (window.popup && !window.popup.closed) {

window.popup.resizeTo(width, height);

}

 

// Set the window properties:

var specs = "location=no, scrollbars=no, menubars=no, toolbars=no, resizable=yes, left=0, top=0, width=" + width + ", height=" + height;

 

// Set the URL:

var url = "show_image.php?image=" + image;

 

// Create the pop-up window:

popup = window.open(url, "ImageWindow", specs);

popup.focus();

 

} // End of function.

//--></script>

</head>

<body>

<p>Click on an image to view it in a separate window.</p>

<table align="center" cellspacing="5" cellpadding="5" border="1">

<tr>

<td align="center"><b>Image Name</b></td>

<td align="center"><b>Image Size</b></td>

</tr>

<?php # Script 10.4 - images.php

// This script lists the images in the uploads directory.

 

$dir = 'C:/wamp/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");

 

// Calculate the image's size in kilobytes:

$file_size = round ( (filesize ("$dir/$image")) / 1024) . "kb";

 

// Make the image's name URL-safe:

$image = urlencode($image);

 

// Print the information:

echo "\t<tr>

\t\t<td><a href=\"javascript:create_window('$image',$image_size[0],$image_size[1])\">$image</a></td>

\t\t<td>$file_size</td>

\t</tr>\n";

 

} // End of the IF.

 

} // End of the foreach loop.

?>

</table>

</body>

</html>

Link to comment
Share on other sites

chris, as I mentioned before, you are getting that error because you have not created a file called show_image.php. And like I said before, go to the index of the book, find show_image.php, go to that page number, and write that script. Then, make sure you put the script in the right folder, and it "should" work, although I have not tested this at all.

 

Actually, I really wish Larry would comment on this, as I am not sure why the show_image.php script is not in the same chapter/section as the 10.4 script.

 

Anyway, I'll look into this a little more thoroughly, but what I can guarantee is that if you don't have a file called show_image.php, you will continue to get this error.

 

Please try what I am recommending, and then let us know what happens.

Link to comment
Share on other sites

Absolutley, I don't have a file call show_image.php I looked at the script you mention at the back of the book script 17.7

The first thing that is mentioned is that this script will do the same thing as the script in chapter 10 except that there are two values been passed to this page

 

Ive looked at the scripts downloaded from the site and there is a script in chapter 10 called show_image.php it is script 10.5, which will explain why i havnt done it yet.

It's the end of chapter 10 'Understanding HTTP headers'

 

Thanks for the support, Ive walked away from this for a week, so it's amusing the answer was on the next page, which i had started to read!

I guess i needed the break.

Regards chris

Link to comment
Share on other sites

 Share

×
×
  • Create New...