Jump to content
Larry Ullman's Book Forums

dg2ben2

Members
  • Content Count

    8
  • Joined

  • Last visited

Community Reputation

1 Neutral

About dg2ben2

  • Rank
    Newbie
  1. Thanks, Antonio, for the help. These were great suggestions and lead me towards where the problem was occurring. My calculator.js file had case insensitivity and either my variables did not match what was being called in the calculator.html file or the functions I was calling in the JS file were not properly called. Ex. Originally, I had $('#taxP').addclass('error'); I then capitalized the 'C' in class throughout my JS file and it worked. Are the built in functions case sensitive in JS or am I on the wrong track?
  2. Exactly. "404- requested URL ....calculator.php was not found on this server."
  3. Okay. Would having the <form action="calculator.php" ....> be taking over for the JS? It seems like I cannot get a request through. I did test the JS out using the test.html and test.js and that worked. But, for this calculator problem, it seems like my JS is not even receiving a request.
  4. Hi Larry, After moving along through the chapter, I had a generic question. For the calculator.js and calculator.html, should my webpage still run even though I do not have calculator.php linked to the HTML? The code is exactly how the book laid out, but when I attempt to test the calculator in a browser and press "Calculate!" I receive a message that calculator.php does not exist and the request cannot be completed. In essence, my question is "Is there something in the browser (Mercury Firefox) that is not loading properly or installed?" or "Does the HTML need both the php and JS to run?". I am currently under the assumption that JS is separate from PHP and can essentially take over the functionality of PHP but keep the requests on the client side. Thanks!
  5. Ah, Magic! Thanks very much. I've wrapped my head around this for days and finally posted about it. Thanks again for the quick response!
  6. i modified line 15/16 and combined them into one line on in the function.js file. That yielded an error regarding an unexpected 'image' on line 15 in the show_image.php script.
  7. Sorry, here is the code with numbers. 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')){ //Check that the image is a file on the server (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); images.php <!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=utf-8" /> <title>Images</title> <!--Include the JavaScript file:--> <script type="text/javascript" charset="utf-8" src="js/function.js"></script> </head> <body> <p>Click on an Image to view in a seperate window:</p> <ul> <?php #Script 11.4 - Images.php //This script lists the images in the uploads directory: $dir = '../uploads'; //Define the directory to pull the images to view $files = scandir($dir); //Read all of the images into the array, $files //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> </html> Function.js // Script 11.3 - function.js //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 It looks like the image is properly referenced in the show_image.php, but when I click on the link I do not get the pop-up.
  8. Hi Larry, I really enjoy your book, but I am having trouble viewing my image after clicking on it. When I comment out the failsafe> unavailable image, I receive a block of code <br /> <font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'> <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined variable: image in C:\wamp\www\Website\show_image.php on line <i>38</i></th></tr> <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr> <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr> <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0004</td><td bgcolor='#eeeeec' align='right'>250856</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\Website\show_image.php' bgcolor='#eeeeec'>..\show_image.php<b>:</b>0</td></tr> </table></font> <br /> <font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'> <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: getimagesize(): Filename cannot be empty in C:\wamp\www\Website\show_image.php on line <i>38</i></th></tr> <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr> <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr> <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0004</td><td bgcolor='#eeeeec' align='right'>250856</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\Website\show_image.php' bgcolor='#eeeeec'>..\show_image.php<b>:</b>0</td></tr> <tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0006</td><td bgcolor='#eeeeec' align='right'>251904</td><td bgcolor='#eeeeec'><a href='http://www.php.net/getimagesize' target='_new'>getimagesize</a> ( )</td><td title='C:\wamp\www\Website\show_image.php' bgcolor='#eeeeec'>..\show_image.php<b>:</b>38</td></tr> </table></font> <br /> <font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'> <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined variable: image in C:\wamp\www\Website\show_image.php on line <i>39</i></th></tr> <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr> <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr> <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0004</td><td bgcolor='#eeeeec' align='right'>250856</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\Website\show_image.php' bgcolor='#eeeeec'>..\show_image.php<b>:</b>0</td></tr> </table></font> <br /> <font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'> <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined variable: image in C:\wamp\www\Website\show_image.php on line <i>47</i></th></tr> <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr> <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr> <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0004</td><td bgcolor='#eeeeec' align='right'>250856</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\Website\show_image.php' bgcolor='#eeeeec'>..\show_image.php<b>:</b>0</td></tr> </table></font> <br /> <font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'> <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: readfile(): Filename cannot be empty in C:\wamp\www\Website\show_image.php on line <i>47</i></th></tr> <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr> <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr> <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0004</td><td bgcolor='#eeeeec' align='right'>250856</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp\www\Website\show_image.php' bgcolor='#eeeeec'>..\show_image.php<b>:</b>0</td></tr> <tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0007</td><td bgcolor='#eeeeec' align='right'>252840</td><td bgcolor='#eeeeec'><a href='http://www.php.net/readfile' target='_new'>readfile</a> ( )</td><td title='C:\wamp\www\Website\show_image.php' bgcolor='#eeeeec'>..\show_image.php<b>:</b>47</td></tr> </table></font> Here is my code: images.php <!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=utf-8" /> <title>Images</title> <!--Include the JavaScript file:--> <script type="text/javascript" charset="utf-8" src="js/function.js"></script> </head> <body> <p>Click on an Image to view in a seperate window:</p> <ul> <?php #Script 11.4 - Images.php //This script lists the images in the uploads directory: $dir = '../uploads'; //Define the directory to pull the images to view $files = scandir($dir); //Read all of the images into the array, $files //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> </html> function.js // Script 11.3 - function.js //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 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')or ($ext == '.JPG') or ($ext == '.JPEG')or ($ext == '.PNG')){ //Check that the image is a file on the server (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);
×
×
  • Create New...