Jump to content
Larry Ullman's Book Forums

chris

Members
  • Posts

    11
  • Joined

  • Last visited

chris's Achievements

Newbie

Newbie (1/14)

1

Reputation

  1. 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
  2. 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>
  3. Hello, Im not quite at the section in the book on sessions and and not able to read php well yet so am probably totally wrong but wouldn't you need and include for mysqli connect?
  4. 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
  5. 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.
  6. 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>
  7. Hi, I have completed Script 10.3, I spent 3 hours last night debbuging it as it would not work. I would select an image and it did nothing. I was using Firefox and dreamweaver cs4, With windows vista, wamp 2.1 php6.0 Apache2.2.17 Ive been trying again today, nothing just the html form.select an image and press submit, i get the load symbol and the form stay's the same! Then i tried Internet explorer 9, nothing Then Opera 11.0, nothing, Then safari, Wa hey... It works, so i tried google chrome and that works too. I noticed the two browsers that work don't have a text box just a button but they work and the images go to the folder So why do the other three browsers that show a text box display not work, is it the way i have them configured as they are the browers i use and the other two i do not? Here is my Script although it is not that!!! <!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>Upload an image</title> <style type="text/css" title="text/css" media="all"> .error { font_weight: bold; color: #c00; } </style> </head> <body> <?Php # Script 10.3 upload_image.php // Check if the form has been submitted: if (isset($_POST['submitted'])) { // Check for an uploaded file if (isset($_FILES['upload'])) { // Validate the file type, should be JPG or PNG. $allowed = array ('image/pjpeg', 'image/jpeg', 'image/jpeg', 'image/JPG', 'image/X_PNG', 'image/PNG', 'image/png', 'image/x-png'); if (in_array($_FILES['upload'] ['type'], $allowed)) { // Move the file over. if (move_uploaded_file ($_FILES['upload']['tmp_name'], "C:/wamp/uploads/{$_FILES['upload']['name'] }")) { echo '<p><em>The file has been uploaded.</em></p>'; } // End of move IF } else { // Invalid type. echo '<p class="error">Please upload a JPG or PNG image.</p>'; } } //End of isset($_FILES['upload']) IF // Check for an error if ($_FILES['upload']['error'] > 0) { echo '<p class="error">The file could not be upload because: <strong>'; //Print a message based upon the error. switch ($_FILES['upload']['error']) { case 1: print 'This exeeds the max_file_upload setting in php.ini.'; break; case 2: print 'The file size exeeds the MAX_FILE_SIZE in the HTML form'; break; case 3: print 'The file was only partialy uploaded.'; break; case 4: print 'No files were uploaded'; break; case 6: print 'No tempory folder was available.'; break; case 7: print 'Unalble to write to the disk'; break; case 8: print 'File upload stopped'; break; default: print 'A sytem error occured'; break; } // End of switch print '</strong></p>'; } // End of error IF. //Delete the files if it still exists if (file_exists ($_FILES['upload']['tmp_name']) && is_file($_FILES['upload']['tmp_name']) ) { unlink ($_FILES['upload']['tmp_name']); } } // End of the submitted conditional ?> <form enctype="multipart/form_data" action="upload_image.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="524288" > <fieldset><legend>Select a JPG or PNG image of 512kb or smaller to be uploaded:</legend> <p><b>File:</b> <input type="file" name="upload" /></p> </fieldset> <div align="center"><input type="submit" name="submit" value="Submit" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> </body> </html>
  8. Hi agaain, ive found the problem. I used a capital P in price on the form. It all now works as it should do. Thanks for the help. I spent hours trying to work out the mistake, i guess walking away helps too.
  9. Thanks for the help,it worked. I used a capital s for submitted and i missed out a t too. It now returns an error message(please enter a valid quantity, price and tax.) after filling out the form and will not calculate.
  10. Hi I am new to php and am stuck on script 3.5 The html form and the includes both work. When i fill out the form and press calculate it clears the form and echo's nothing back I spent hour's last night trying to see where i have gone wrong Im using wamp 2.1 which had php 5.3.5 and ive now used an add on 6.0 as i thought it may be that Thanks Chris
  11. <?php # Script 3.5 calculator.php $page_title = 'widget cost calculator'; include('includes/header.html'); // Check for form submission if(isset($_POST['submitted'])) { //Minimal form validation if ( is_numeric($_POST['quantity'])&& is_numeric($_POST['price'])&& is_numeric($_POST['tax']) ){ //calculte the results $total = ($_POST['quantity']* $_POST['price']); $taxrate = ($_POST['tax'] / 100); //turn 5% into .05. $total += ($total * $taxrate); // Add tax //Print the results echo '<h1>Total cost</h1> <p>The total cost of purchasing '. $_POST['quantity'] .' widget(s) at $'.number_format ($_POST['price'], 2).' each, including a tax rate of'. $_POST['tax'] .'%, is $'.number_format ($total, 2).'.</p>'; } else { // Invalid submited values. echo '<h1>Error!</h1> <p class="error">Please enter a valid quantity, price, and tax.</p>'; } } // End of main isset() If. // Leave the php section and create the html form ?> <h1>Widget cost calculator</h1> <form action="calculator.php" method="post"> <p>Quantity: <input type="text" name="quantity" size="5" maxlength="5" /> </p> <p>Price: <input type="text" name="Price" size="5" maxlength="10" /> </p> <p>Tax (%): <input type="text" name="tax" size="5" maxlength="5" /> </p> <p> <input type="submit" name="submit" value="calculate" /> </p> <input type="hidden" name="Submited" value="1" /> </form> <?php //Include footer include ('includes/footer.html'); ?>
×
×
  • Create New...