Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'chapter 11'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 6 results

  1. OS: Windows 7 php version: 5.5.8 (running on EasyPHP Dev Server 14.1 VC11) Browser: Firefox 40.0.2 (same results in Chrome and IE) I am having problems with the show_image script in chapter 11. When I select an image from the list it opens a popup window of the appropriate size but with no image. In firefox I get the error message: 'The image "http://127.0.0.1/scripts/site/show_image.php?image=Picture.png"cannot be displayed because it contains errors.' When I use the Web Developer menu to View Response Headers all is as expected except that it lists Content-Length: 0. I commented out the header calls and replaced them with echos: echo "Content-Type: {$info['mime']}</br>"; echo "Content-Disposition: inline; filename=\"$name\"</br>"; echo "Content-Length: $fs"; Which return the values you would expect: Content-Type: image/png Content-Disposition: inline; filename="Picture.png" Content-Length: 35880 I changed the Content-Disposition to attachment. The files download as normal with the appropriate file names but have a size of 0. When I try to open them I get the error message: "Windows Photo Viewer can't display this picture because the file is empty." I double checked the files in the upload folder and they are all normal .png files. My code is below. Any advice you can offer would be very gratefully received. Adam show_image.php <?php $name = FALSE; if (isset($_GET['image'])) { //echo 'Image set </br>'; $ext = strtolower(substr($_GET['image'], -4)); if (($ext == '.jpg') OR ($ext == 'jpeg') OR ($ext == '.png')) { //echo 'Correct ext </br>'; $image = "../uploads/{$_GET['image']}"; if (file_exists($image) && (is_file($image))) { //echo 'File exists </br>'; $name = $_GET['image']; } } } if (!$name) { //echo 'Unavailable'; $image = 'images/unavailable.png'; $name = 'unavailable.png'; } $info = getimagesize($image); $fs = filesize($image); header ("Content-Type: {$info['mime']}\n"); header ("Content-Disposition: inline; filename=\"$name\"\n"); header ("Content-Length: $fs"); //echo "Content-Type: {$info['mime']}</br>"; //echo "Content-Disposition: inline; filename=\"$name\"</br>"; //echo "Content-Length: $fs"; images.php <!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//EN" "http:/www.w3.org/TR/xhtml/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> <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 $dir = '../uploads'; $files = scandir($dir); foreach ($files as $image) { if (substr($image, 0 , 1) != '.') { $image_size = getimagesize ("$dir/$image"); $image_name = urlencode($image); echo "<li><a href=\"javascript:create_window('$image_name',$image_size[0],$image_size[1])\">$image</a></li>\n"; } } ?> </ul> </body> </html> function.js // Script 11.3 - function.js function create_window (image, width, height) { width = width + 10; height = height + 10; if (window.popup && !window.popup.closed) { window.popup.resizeTo(width, height); } 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(); }
  2. I'm working through Larry's PhP 6 and MySqL 5 book which so far has been excellent but I've hit a snag I can't get past. On Chapter 11 'Cookies & Sessions' I've completed page 327 - 339 and when I test my pages on my MacOSX running Xampp I get errors shown below. Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/php/mysqli_connect.php:4) in /Applications/XAMPP/xamppfiles/htdocs/php/ch11/login.php on line 23 Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/php/mysqli_connect.php:4) in /Applications/XAMPP/xamppfiles/htdocs/php/ch11/login.php on line 24 Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/php/mysqli_connect.php:4) in /Applications/XAMPP/xamppfiles/htdocs/php/ch11/login.php on line 28 I've checked the code and removed all the spaces after the final ?> php tag but I still get the error. Could you help please, many thanks in advance. Below is the code on 'Login.php' Line 23/24 is the setcookie function Line 28 is the header function <?php # Script 9.3 - login.php // This page processes the login form submission. // Upon successful login, the user is redirected. // Two included files are necessary. // Send NOTHING to the Web browser prior to the setcookie() lines! // Check if the form has been submitted: if (isset($_POST['submitted'])) { // For processing the login: require_once ('includes/login_functions.inc.php'); // Need the database connection: require_once ('../mysqli_connect.php'); // Check the login: list ($check, $data) = check_login($dbc, $_POST['email'], $_POST['pass']); if ($check) { // OK! // Set the cookies: setcookie ('user_id', $data['user_id']); setcookie ('first_name', $data['first_name']); // Redirect: $url = absolute_url ('loggedin.php'); header("Location:$url"); exit(); // Quit the script. } else { // Unsuccessful! // Assign $data to $errors for error reporting // in the login_page.inc.php file. $errors = $data; } mysqli_close($dbc); // Close the database connection. } // End of the main submit conditional. // Create the page: include ('includes/login_page.inc.php'); ?>
  3. Hi Larry, would like to say great book, has really helped me out with my understanding of PHP and OOP. On p358, when using the mkdir() command, would it not be preferable to set the recursive parameter to TRUE? So line 23 of db_backup.php is: if (!@mkdir($dir, 0777, true)) { My script wasn't creating the directories as expected until I set this to TRUE, by default it is set to FALSE. Cheers Noel
  4. 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);
  5. Chapter 11 prusue #4 says: Change add_quote.php so that it takes the quotation and the attribution as separate inputs and writes them separately to the text file. Then modify view_quote.php so that it retrieves and displays both the pieces of data. What does it mean by the 'attribution'? Thanks Tim
×
×
  • Create New...