Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Beginning PHP 5.3
|
BOOK: Beginning PHP 5.3
This is the forum to discuss the Wrox book Beginning PHP 5.3 by Matt Doyle; ISBN: 978-0-470-41396-8
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 5.3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 11th, 2011, 01:51 AM
Authorized User
 
Join Date: Jun 2011
Posts: 51
Thanks: 9
Thanked 0 Times in 0 Posts
Send a message via MSN to nawar youssef
Cool Help with the Uploading photo example

I checked many times and I think I did not miss anything but still the code does not work exactly, and when I click "sendPhoto" the browser gives me a message with that the URL are not found and I am sure I have the image in the root file.
this is the code if anybody have time to check it, thanks
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <style rel="stylesheet" type="text/css" href="common.css"></style>
</head>
 <body>
  <?php
  
  
if ( isset($_POST["sendPhoto"]) ) {
      
processForm();
  } else {
      
displayForm();
  }
  
  function 
processForm() {
  
      if ( isset(
$_FILES["photo"]) and $_FILES["photo"]["error"]==UPLOAD_ERR_OK ) {
        
        if ( 
$_FILES["photo"]["type"] != "image/jpeg" ) {
            echo 
"<p>JPEG only allowed, thanks.</p>";
        } elseif ( !
move_uploaded_file$_FILES["photo"]["tmp_name"], "photos/" basename($_FILES["photo"]["name"]) ) ) {
            echo 
"<p>Sorry there is something went wrong with uploading your photo !!!</p>" $_FILES["photo"]["error"];
        } else {
         
displayThanks();
        }
        
      } else {
          switch ( 
$_FILES["photo"]["error"] ) {
              case 
UPLOAD_ERR_INI_SIZE:
                  
$message "the photo is too large for the server !!!";
                  break;
              case 
UPLOAD_ERR_FORM_SIZE:
                  
$message "the photo is too large for the script !!!";
                  break;
              case 
UPLOAD_ERR_NO_FILE:
                  
$message "no file was upload. make sure you choose a file !!!";
                  break;
              default:
                  
$message "Please contact your server help";
          }
          echo 
"<p> SORRY !!!, ther was a problem uploading your photo . $message</p>";
      }
  
  }
  
  function 
displayForm() {
     
?>
         <h1> Uploading a Photo </h1>
         <p> Please enter your name and choose a photo to upload, then click send photo.</p>
         <form action="photo-upload.php" method="post" enctype="multipart/form-data">
          <div style="width:30em;">
          <input type="hidden" name="MAX_FILE_SIZE" value="50000" />
          
           <label for="visitorName">your name : </label>
           <input type="text" name="visitorName" id="visitorName" value="" />
           
           <label for="photo">your photo : </label>
           <input type="file" name="photo" id="photo" value="" />
           
           <div style="clear:both">
               <input type="submit" name="sendPhoto" value="Send Photo" />
           </div>
           
          </div>
         </form>
         
     <?php
     
}
     
     function 
displayThanks() {
     
?>
     <h1> Thank You </h1>
     <p>thank you for uploading your photo <?php if($_POST["visitorName"]) echo ", " $_POST["visitorName"?> !!! </p>
     <p> Here is you photo !!! </p>
     <p><img src="photo/<?php echo $_FILES["photo"]["name"?>" alt="Photo" /></p>
     <?php
     
}
  
?>
  
 </body>
</html>
 
Old September 11th, 2011, 10:32 AM
Authorized User
 
Join Date: May 2010
Posts: 70
Thanks: 4
Thanked 6 Times in 6 Posts
Send a message via Yahoo to GeneBuchite
Default Check the filename

If you are getting the 404 ; File not found error, the file name must be spelled wrong or something similar. chek the file name... they must match exactly, caps. and all.
 
Old September 12th, 2011, 01:48 AM
Authorized User
 
Join Date: Jun 2011
Posts: 51
Thanks: 9
Thanked 0 Times in 0 Posts
Send a message via MSN to nawar youssef
Default hey, you know !!!

you know that I correct the code and the problem was about the name or lowercase and uppercase for one of the function, I do not remember exactly.
thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Listview with photo horses60 BOOK: Beginning ASP.NET 4 : in C# and VB 2 April 10th, 2011 10:12 AM
Error posting photo to photo album abel714 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 10 February 5th, 2007 03:07 AM
Photo software malambing57 ASP.NET 1.0 and 1.1 Professional 1 January 9th, 2007 11:50 AM
Display 'no photo' in a JSP when photo is not pres Inderjeet Pro JSP 0 April 21st, 2006 05:35 AM
fading from photo to photo in flash elladi Flash (all versions) 1 November 28th, 2004 11:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.