bluedaniel Posted January 9, 2009 Share Posted January 9, 2009 Ok so Ive got an upload form for a recipes website im creating. This handler works perfect in Google Chrome, No errors in firefox but doesnt work. IE gives a filesize error. How is this possible? Newrecipe.php: <?php require_once("includes/connection.php"); ?> <?php require_once("includes/session.php"); ?> <?php require_once("includes/functions.php"); ?> <?php confirm_logged_in(); ?> <?php $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/noimage.jpg', '/_images/_pic/noimage_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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 9, 2009 Share Posted January 9, 2009 For IE, the code is testing both the ['type'] and ['size'] in one conditional statement and reports - Error: Only .jpg images under 350Kb are accepted for upload. So, you will never know which comparison failed. Rewrite the code so that you test for and report each possible error separately (hint: the ['type'] that IE sends is probably not "image/jpeg".) Which beings up another point, error messages that don't have anything to due with security should display the actual values so that you can see what was being compared. For FF, define: "but doesnt work" What does it do? What do you see in front of you? Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733487 Share on other sites More sharing options...
bluedaniel Posted January 9, 2009 Author Share Posted January 9, 2009 When it works in Google Chrome the page redirects to a share.php addy. Firefox does the same but no information at all is inserted into the SQL database. Ill try sorting out that IE error now Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733489 Share on other sites More sharing options...
bluedaniel Posted January 9, 2009 Author Share Posted January 9, 2009 Just to let you know that IE inserts the info fine when not uploading a picture, so Im assuming it is that 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; bit of code, im not sure how to rework that however Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733491 Share on other sites More sharing options...
PFMaBiSmAd Posted January 9, 2009 Share Posted January 9, 2009 For FF, does the move_uploaded_file() produce a file? Which code is responsible for the redirect to share.php? The header("Location: allrecipes.php"); or something that <?php confirm_logged_in(); ?> does? The easiest and best way to test for multiple possible values for the ['type'] is to make an array of the possible values and use in_array in the conditional test. Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733496 Share on other sites More sharing options...
bluedaniel Posted January 9, 2009 Author Share Posted January 9, 2009 Yeah <?php confirm_logged_in(); ?> redirects to share.php FF does not upload an image either, ill try reworking that if statement but im a bit of a rookie Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733503 Share on other sites More sharing options...
PFMaBiSmAd Posted January 9, 2009 Share Posted January 9, 2009 Yeah <?php confirm_logged_in(); ?> redirects to share.php That would indicate you have a login problem that you need to troubleshoot and the rest of the code on that page is not being executed anyway. Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733507 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 Just a side note, not related to the problem: <?php require_once("includes/connection.php"); ?> <?php require_once("includes/session.php"); ?> <?php require_once("includes/functions.php"); ?> <?php confirm_logged_in(); ?> <?php Why do that? This would be much easier: <?php require_once("includes/connection.php"); require_once("includes/session.php"); require_once("includes/functions.php"); confirm_logged_in(); There is really no reason to put them in their own <?php ?> tags... Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733512 Share on other sites More sharing options...
bluedaniel Posted January 9, 2009 Author Share Posted January 9, 2009 Thanks for the help thus far people, Ive managed to workaround it so it works perfectly in both Google and now IE!!! trouble is firefox is still playing up if (($ext == "jpg") && ($_FILES["uploaded_pic"]["size"] < 350000)) { //Determine the path to which we want to save this file I removed the image verification completely as the above code checks if its a jpg anyway. Any ideas what problem firefox has with this now? Im so close!!! Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733551 Share on other sites More sharing options...
bluedaniel Posted January 9, 2009 Author Share Posted January 9, 2009 If anyone would like my work files then let me know Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733559 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 If anyone would like my work files then let me know Honestly, the three browsers should not make a difference in either. What most likely is the issue is your form, so post the HTML code for that form/page that you use for the upload process. Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733560 Share on other sites More sharing options...
bluedaniel Posted January 9, 2009 Author Share Posted January 9, 2009 <!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>What Can I Cook | Upload Your Recipe</title> <link REL="SHORTCUT ICON" HREF="_images/favicon.ico"> <link href="/_css/base.css" rel="stylesheet" type="text/css" /> <link href="/_css/uploadrecipe.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="wrapper"> <div id="header"> <h1>What Can I Cook?</h1> <div id="logoImage"></div> <ul id="mainNav"> <li><a href="index.html">Home </a></li> <li><a href="allRecipes.php">Recipes </a></li> <li><a href="features.php">Features </a></li> <li><a href="blogs.php">Blogs </a></li> <li><a href="forum.php">Forum </a></li> <li><a href="share.php">Share </a></li> <li><a href="shop.html">Shop </a></li> </ul> </div> <div id="content"> <h1>Add your Recipe</h1> <p>We have tried to make this as painless as possible for you, below are the fields you can enter your information into and we have written tips and examples to the right of them to help smooth the process.</p> <form enctype="multipart/form-data" form id="form1" name="form1" method="post" action="newrecipe.php"> <table width="801" border="0" id="recipeupload2"> <tr> <td width="169" valign="top"><h1> Recipe Title: <label></label> </h1></td> <td width="622" valign="top"><input name="title" type="text" id="title" size="60" maxlength="60" /> </td> </tr> <tr> <td valign="top"> </td> <td valign="top"><p>Please choose your title carefully, it should be descriptive to other users.</p></td> </tr> <tr> <td valign="top"><h1>Small Description: <label></label> </h1></td> <td valign="top"><textarea name="smalldesc" cols="60" rows="3" id="smalldesc"></textarea> </td> </tr> <tr> <td valign="top"> </td> <td valign="top"><p>This will appear when a user searches for a recipe, this small description could be why you like this recipe or why others will want to try it. e.g. a Quick and Simple hearty meal etc.</p></td> </tr> <tr> <td valign="top"><h1>Ingredients: <label></label> </h1></td> <td valign="top"><textarea name="ingredients" cols="60" rows="5" id="ingredients">100g pasta, 4 chicken breasts, grated cheese</textarea> </td> </tr> <tr> <td valign="top"> </td> <td valign="top"><p>NOTE: To seperate each ingredient use a comma (,). If you use a comma then anything after that will be shown as a new item, above is the way you should type your ingredients.</p></td> </tr> <tr> <td valign="top"><h1>Method: <label></label> </h1></td> <td valign="top"><textarea name="method" cols="60" rows="5" id="method"></textarea> </td> </tr> <tr> <td valign="top"> </td> <td valign="top"><p>Separate steps using paragraphs, hit "enter" key. Do not number steps (we'll do that for you). </p></td> </tr> <tr> <td valign="top"><h1>Time: <label></label> </h1></td> <td valign="middle"><input type="text" name="time" id="time" /></td> </tr> <tr> <td valign="top"> </td> <td valign="top"><p>How long will it take to make this recipe? This is a total figure with preperation taken into account.</p></td> </tr> <tr> <td valign="top"><h1>Servings: <label></label> </h1></td> <td valign="middle"><input type="text" name="amount" id="amount" /></td> </tr> <tr> <td valign="top"> </td> <td valign="top"><p>How many servings will this recipe make? e.g You could type 'X Portions', 'X Helpings' or 'X Cookies'</p></td> </tr> <tr> <td valign="top"><h1>Upload Picture:</h1></td> <td valign="top"><label> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> <input name="uploaded_pic" type="file" /> </label></td> </tr> <tr> <td valign="top"> </td> <td valign="top"><p>This is greatly encouraged as it will make your recipe really stand out from the crowd, the dimensions will be 235px by 215px. It must be a jpeg image and not exceed 350kb in size.</p></td> </tr> <tr> <td valign="top"><h1>Keywords: <label></label> </h1></td> <td valign="top"><textarea name="keywords" cols="60" rows="2" id="keywords"></textarea></td> </tr> <tr> <td valign="top"> </td> <td valign="top"><p>This is for our search engine, it could be anything you like and will mean that the words above will make your recipe appear when someone searches for that word. You could leave this blank if want.</p></td> </tr> <tr> <td colspan="2" valign="top"><label> <input type="button" name="cancel" id="cancel" value="Cancel" onclick="history.back()" /> <input type="submit" name="continue" id="continue" value="Continue" /> </label></td> </tr> </table> </form> </div> <div id="clear"></div> <div id="footer">© 2007 Cheek Chastain Gallery. No portion of this website or artwork portrayed herein may be redistributed of republished without the expressed consent of Cheek Chastain Gallery. View our full legal disclaimer here.</div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733564 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 <form enctype="multipart/form-data" form id="form1" name="form1" method="post" action="newrecipe.php"> Should be: <form enctype="multipart/form-data" id="form1" name="form1" method="post" action="newrecipe.php"> The rest look fine, try changing that and see if it fixes your results. Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733573 Share on other sites More sharing options...
bluedaniel Posted January 9, 2009 Author Share Posted January 9, 2009 still no luck in firefox, cant for the live of me work this out Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733599 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 still no luck in firefox, cant for the live of me work this out Try searching the forums, about 2-3 days ago a guy had the same problem with uploading and firefox, I cannot remember what the solution was, but maybe it will work here too. Found it: http://www.phpfreaks.com/forums/index.php/topic,230310.msg1067826.html#msg1067826 Edit: Linked to the answer of the post. I think I just found out what is happening. FF is reading ">= 20000" as 20000 bytes, and IE is reading it as kb. I don't know why. But that is what seems to be happening from my tests. so I changed it to 21000000 and it works in FF, but now people can upload massive files in IE. Oh well, I guess as close to a fix as I can hope. Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733602 Share on other sites More sharing options...
bluedaniel Posted January 9, 2009 Author Share Posted January 9, 2009 Still no luck even with that change Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733614 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 Well, I highly doubt this is the problem, cause I do it all the time too, but who knows. Try changing each form field id="fieldname_id" and see what that does. If that still does not work, are you sure your errors are turned on to display errors and see if any errors are coming through? The next step would be, in the PHP file, try removing an include and see if it displays anything, then add it back in and try the next. It could be an error in your pages, but why it would trigger on separate browsers I do not know. You could also try adding ob_start before the first include and see if it works or not. Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733616 Share on other sites More sharing options...
PFMaBiSmAd Posted January 9, 2009 Share Posted January 9, 2009 Add the following code to your upload processing page to see what exactly is being sent - echo "<pre>"; echo "POST:"; print_r($_POST); echo "FILES:"; print_r($_FILES); echo "</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/140171-different-behaviours-for-3-different-browsers/#findComment-733618 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.