coolphpdude Posted March 24, 2009 Share Posted March 24, 2009 Hi people! I've got this image upload script which im having a few problems with (please find the code below) Form: echo "<form enctype='multipart/form-data' method='post' action=uploadpicture.php'>"; echo "<input type='hidden' name='max_file_size' value='10000000' />"; echo "<input name='uploadedfile' type='file'>"; echo "<br>"; echo "<br>"; echo "<input type='submit' value='Upload Picture' >"; echo "</form>"; Now this should mean that the max file size of the picture that is to be uploaded should be no larger than 10mb. Code: $uploadedfile=$_POST["uploadedfile"]; function resampleimage($maxsize, $sourcefile, $destination, $imgcomp=0){ // SET THE IMAGE COMPRESSION $g_imgcomp=100-$imgcomp; // CHECK TO SEE IF THE IMAGE EXISTS FIRST if(file_exists($sourcefile)){ // FIRST WE GET THE CURRENT IMAGE SIZE $g_is=getimagesize($sourcefile); /********* CALCULATE THE WIDTH AND THE HEIGHT ***************/ // CHECK TO SEE IF THE WIDTH AND HEIGHT ARE ALREADY SMALLER THAN THE MAX SIZE if($g_is[0] <= $maxsize && $g_is[1] <= $maxsize){ // LEAVE WIDTH AND HEIGHT ALONE IF IMAGE IS SMALLER THAN MAXSIZE $new_width=$g_is[0]; $new_height=$g_is[1]; } else { // GET VALUE TO CALCULATE WIDTH AND HEIGHT $w_adjust = ($maxsize / $g_is[0]); $h_adjust = ($maxsize / $g_is[1]); // CHECK TO WHICH DIMENSION REQUIRES THE SMALLER ADJUSTMENT if($w_adjust <= $h_adjust){ // CALCULATE WIDTH AND HEIGHT IF THE WIDTH VALUE IS SMALLER $new_width=($g_is[0]*$w_adjust); $new_height=($g_is[1]*$w_adjust); } else { // CALCULATE WIDTH AND HEIGHT IF THE HEIGHT VALUE IS SMALLER $new_width=($g_is[0]*$h_adjust); $new_height=($g_is[1]*$h_adjust); } } //SEARCHES IMAGE NAME STRING TO SELECT EXTENSION (EVERYTHING AFTER THE LAST "." ) $image_type = strrchr($sourcefile, "."); //changes the file extension from uppercase to lowercase $lower = strtolower($image_type); //SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION switch($lower) { case '.jpg': $img_src = imagecreatefromjpeg($sourcefile); break; case '.jpeg': $img_src = imagecreatefromjpeg($sourcefile); break; case '.png': $img_src = imagecreatefrompng($sourcefile); break; case '.gif': $img_src = imagecreatefromgif($sourcefile); break; default: echo("Error Invalid Image Type"); die; break; } // CREATE THE TRUE COLOR IMAGE WITH NE WIDTH AND HEIGHT $img_dst=imagecreatetruecolor($new_width,$new_height); // RESAMPLE THE IMAGE TO NEW WIDTH AND HEIGHT imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $new_width, $new_height, $g_is[0], $g_is[1]); // OUTPUT THE IMAGE AS A JPEG. // THIS CAN BE CHANGED IF YOU WANT TRANSPARENCY OR PREFER ANOTHER FORMAT. MAKE SURE YOU CHANGE HEADER ABOVE. imagejpeg($img_dst, $destination, 100); // DESTROY THE NEW IMAGE imagedestroy($img_dst); return true; } else { return false; } } // INSERT PICTURE CODE - START if ((($_FILES["uploadedfile"]["type"] == "image/pjpeg") || ($_FILES["uploadedfile"]["type"] == "image/jpeg") || ($_FILES["uploadedfile"]["type"] == "image/JPEG") || ($_FILES["uploadedfile"]["type"] == "image/png") || ($_FILES["uploadedfile"]["type"] == "image/bmp")) && ($_FILES["uploadedfile"]["size"] < 10000000)) { echo "file uploaded"; } else { echo "file not uploaded"; } to me this all looks fine and i should be able to upload any picture with most image file types but they must be under 10Mb!! well for some reason im tryin to upload a .jpg thats 2.5mb and it won't work. Any ideas??? Cheers Link to comment https://forums.phpfreaks.com/topic/150886-picture-upload/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 24, 2009 Share Posted March 24, 2009 What does the following code give for an upload file size that does not work - echo "<pre>"; echo "POST:"; print_r($_POST); echo "FILES:"; print_r($_FILES); echo "</pre>"; Link to comment https://forums.phpfreaks.com/topic/150886-picture-upload/#findComment-792657 Share on other sites More sharing options...
coolphpdude Posted March 24, 2009 Author Share Posted March 24, 2009 POST:Array ( [max_file_size] => 100000000 ) FILES:Array ( [uploadedfile] => Array ( [name] => DSCN0026.JPG [type] => [tmp_name] => [error] => 1 => 0 ) ) Link to comment https://forums.phpfreaks.com/topic/150886-picture-upload/#findComment-792666 Share on other sites More sharing options...
PFMaBiSmAd Posted March 24, 2009 Share Posted March 24, 2009 All code must check for errors before attempting to use data that might not exists - http://us3.php.net/manual/en/features.file-upload.errors.php Link to comment https://forums.phpfreaks.com/topic/150886-picture-upload/#findComment-792669 Share on other sites More sharing options...
coolphpdude Posted March 24, 2009 Author Share Posted March 24, 2009 so does that mean theres a max file size set in the php.ini file thats effecting this even though i have set different perameters in the code?? Link to comment https://forums.phpfreaks.com/topic/150886-picture-upload/#findComment-792671 Share on other sites More sharing options...
lonewolf217 Posted March 24, 2009 Share Posted March 24, 2009 yes, you should always set the max file size for uploads in php.ini it looks like this ; Maximum allowed size for uploaded files. upload_max_filesize = 100M post_max_size = 100M Link to comment https://forums.phpfreaks.com/topic/150886-picture-upload/#findComment-792673 Share on other sites More sharing options...
coolphpdude Posted March 24, 2009 Author Share Posted March 24, 2009 right, i get you now!! I was messing about trying different things for hours yesterday! do you know where php.ini will be located on my hosting?? Link to comment https://forums.phpfreaks.com/topic/150886-picture-upload/#findComment-792683 Share on other sites More sharing options...
coolphpdude Posted March 24, 2009 Author Share Posted March 24, 2009 sorted!! cheers guys! Link to comment https://forums.phpfreaks.com/topic/150886-picture-upload/#findComment-792720 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.