Different behaviours for 3 different browsers!!

Discussion in 'PHP' started by bluedaniel, Jan 9, 2009.

  1. #1
    Ok so Ive got an upload form for a recipes website im creating.
    This handler works perfect in Google Chrome,
    Firefox spits out no errors and no information at all is inserted into the SQL database.
    IE gives a filesize error but works if no image is uploaded.

    How is this possible????

    <?php 
    require_once("includes/connection.php"); 
    require_once("includes/session.php"); 
    require_once("includes/functions.php"); 
    confirm_logged_in(); 
    
    	$title = $_POST['title'];
    	$smalldesc = $_POST['smalldesc'];
    	$ingredients = $_POST['ingredients'];
    	$method = $_POST['method'];
    	$time = $_POST['time'];
    	$amount = $_POST['amount'];
    	$keywords = $_POST['keywords'];
    
    ?>
    <?php
    //check that we have a file
    if((!empty($_FILES["uploaded_pic"])) && ($_FILES['uploaded_pic']['error'] == 0)) {
      //Check if the file is JPEG image and it's size is less than 350Kb
    $file = basename($_FILES['uploaded_pic']['name']);
    $file = "testingtxt.jpg";
    list($file, $ext) = explode(".", $file);
    $filename = $_POST['title'].".".$ext;
      $ext = substr($filename, strrpos($filename, '.') + 1);
      if (($ext == "jpg") && ($_FILES["uploaded_pic"]["type"] == "image/jpeg") && 
        ($_FILES["uploaded_pic"]["size"] < 350000)) {
        //Determine the path to which we want to save this file
          $newname = dirname(__FILE__).'/_images/_pic/'.$filename;
          //Check if the file with the same name is already exists on the server
          if (!file_exists($newname)) {
            //Attempt to move the uploaded file to it's new place
            if ((move_uploaded_file($_FILES['uploaded_pic']['tmp_name'],$newname))) {
    		   echo "It's done! The file has been saved as: ".$newname;
    		   
    		   $thumb = dirname(__FILE__).'/_images/_pic/'.$_POST['title']." _thumb.".$ext;
               createThumb($newname, $thumb);
    		   
    		   $img = dirname(__FILE__).'/_images/_pic/'.$_POST['title'].".".$ext;
               resize($newname, $img);
    		   
    		   $query = "INSERT INTO recipes (
    				Title, Smalldesc, Ingredients, Method, Time, Amount, Keywords, Created_at, Picture, Picturesmall
    			) VALUES (
    			'{$title}', '{$smalldesc}', '{$ingredients}', '{$method}', '{$time}', '{$amount}', '{$keywords}', NOW(), '/_images/_pic/$title.jpg', '/_images/_pic/$title _thumb.jpg')";
    			if (mysql_query($query, $connection)) {
    				header("Location: allrecipes.php");
    				exit;
    			} else {
    					echo "<p>Recipe not entered.</p>";
    					echo "<p>" . mysql_error() . "</p>";
    				}
    		   
            } else {
               echo "Error: A problem occurred during file upload!";
            }
          } else {
             echo "Error: File ".$_FILES["uploaded_pic"]["name"]." already exists";
          }
      } else {
         echo "Error: Only .jpg images under 350Kb are accepted for upload";
      }
    } else {
    	$query = "INSERT INTO recipes (
    				Title, Smalldesc, Ingredients, Method, Time, Amount, Keywords, Created_at, Picture, Picturesmall
    			) VALUES (
    			'{$title}', '{$smalldesc}', '{$ingredients}', '{$method}', '{$time}', '{$amount}', '{$keywords}', NOW(), '/_images/_pic/1000.jpg', '/_images/_pic/1000 _thumb.jpg')";
    			if (mysql_query($query, $connection)) {
    				header("Location: allrecipes.php");
    				exit;
    			} else {
    					echo "<p>Recipe not entered.</p>";
    					echo "<p>" . mysql_error() . "</p>";
    				}
     echo "Error: No file uploaded";
    }
    ?>
    
    <?php mysql_close($connection); ?>
    Code (markup):

     
    bluedaniel, Jan 9, 2009 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    That's realy weird, coz the server handles the data and not the browser, it only sends the data
     
    EricBruggema, Jan 13, 2009 IP