phillips321 Posted September 24, 2007 Share Posted September 24, 2007 Hi guys, I've found a fault in my php script, when i try to upload a file sometimes if the file is too large it wont report the size of it. This simple code should just work, i'm unsure as to why it doesn't. If i upload an small image (<1MB) everything works fine,but sometimes if i upload a larger image it doesn't report the size? Any one here got any ideas?? Cheers <html> <head> <title>ForumPix Uploader</title> </head> <body> <center> <form enctype="multipart/form-data" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="94096000"/> Your file:<input name="upload" type="file"> <input type="submit" value="Upload!"> </form> <?php $size = $_FILES['upload']['size']; $type = $_FILES['upload']['type']; $name = $_FILES['upload']['tmp_name']; echo ' size='.$size; echo ' type='.$type; echo ' name='.$name; ?> </center> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/70470-size-_filesuploadsize-fault-in-php/ Share on other sites More sharing options...
phillips321 Posted September 24, 2007 Author Share Posted September 24, 2007 P.s. please test it at http://www.forumpics.co.uk Quote Link to comment https://forums.phpfreaks.com/topic/70470-size-_filesuploadsize-fault-in-php/#findComment-354024 Share on other sites More sharing options...
quickstopman Posted September 24, 2007 Share Posted September 24, 2007 <html> <head> <title>ForumPix Uploader</title> </head> <body> <center> <form enctype="multipart/form-data" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="94096000"/> Your file:<input name="upload" type="file"> <input type="submit" value="Upload!"> </form> <?php $size = $_FILES['upload']['size']; $type = $_FILES['upload']['type']; $name = $_FILES['upload']['tmp_name']; if (!$size > "94096000") { echo ' size='.$size; echo ' type='.$type; echo ' name='.$name; } else { echo 'The file you uploaded was '. $size; } ?> </center> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/70470-size-_filesuploadsize-fault-in-php/#findComment-354084 Share on other sites More sharing options...
phillips321 Posted September 24, 2007 Author Share Posted September 24, 2007 I have tested this code and it still doesn't work... Something really isn't right. Can you possibly try uploading a BMP or a large picture to http://www.forumpix.co.uk Cheers Quote Link to comment https://forums.phpfreaks.com/topic/70470-size-_filesuploadsize-fault-in-php/#findComment-354326 Share on other sites More sharing options...
darkfreaks Posted September 24, 2007 Share Posted September 24, 2007 if ($size > "94096000") { Quote Link to comment https://forums.phpfreaks.com/topic/70470-size-_filesuploadsize-fault-in-php/#findComment-354329 Share on other sites More sharing options...
phillips321 Posted September 24, 2007 Author Share Posted September 24, 2007 nope thats not it either. I have literally looked into this code like a madman but something with php aint right. Any chance someone could quickly use the php code on their server and test uploading a file to it? (try uploading a file greater than 2048KB - i would be very greatful if someone else could reproduce the error) 4 files + 1 directory needed: index.php (the actual code) overlay.png (the overlayed logo) background.gif upcount.txt (the upload text counter) uploads/ (a directory to write the uploaded images to) all files are packed in this zip here (11KB) http://phillips321.getmyip.com/dumping_ground/forumpix.zip here's the code for reference: <html> <head> <title>ForumPix Uploader</title> <SCRIPT TYPE="text/javascript"> <!-- function popup(mylink, windowname) { if (! window.focus)return true; var href; if (typeof(mylink) == 'string') href=mylink; else href=mylink.href; window.open(href, windowname, 'width=400,height=300,scrollbars=no'); return false; } //--> </SCRIPT> </head> <body background="background.gif" TEXT="#FFFFFF" LINK="FF6600" VLINK="FF6600"> <!--Changed theme to personalise--> <center> <PRE> __ _ _ / _| (_) | | | |_ ___ _ __ _ _ _ __ ___ _ __ ___ __ ___ ___ _ _| | __ | _/ _ \| '__| | | | '_ ` _ \| '_ \| \ \/ / / __/ _ \ | | | | |/ / | || (_) | | | |_| | | | | | | |_) | |> < _ | (_| (_) | _ | |_| | < |_| \___/|_| \__,_|_| |_| |_| .__/|_/_/\_\ (_) \___\___/ (_) \__,_|_|\_\ | | |_| </PRE> <form enctype="multipart/form-data" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="4096000"/> Your file:<input name="upload" type="file"> <font size="1"> <A HREF="TandCs.html" onClick="return popup(this, 'notes')">Accept T&Cs</A> </font> <input type="checkbox" name="tac" value="1" /> <input type="submit" value="Upload!"> </form> <?php $countpath = 'upcount.txt'; //sets location of counter file $resize = '1000'; //sets max width or height of image $url = 'http://forumpix.getymyip.com'; //url of site (dont not include trainling "/" $overlay = 'overlay.png'; $quality = '60'; //user sets quality of jpg image $fail = '0'; $img_resized = '0'; $size = $_FILES['upload']['size']; $type = $_FILES['upload']['type']; $name = $_FILES['upload']['tmp_name']; if ($_POST['tac'] == 1){$tac = 1;} else {$tac = 0;} if ($name != UPLOAD_ERR_OK){$fail = 'Error uploading file!';} //checks for upload error if ($size == 0){$fail = 'Error: uploaded file is empty!';} //file size check if ($size > '4096000') {$fail = 'File was too big - please upload one smaller than 1MB.';} //checks uploaded file size if ($tac == 0){$fail = 'Please acccept the terms and conditions';} if($fail == '0'){ //echo '<BR>FILE Type Check running'; if ($type == 'image/jpeg') {$img = imagecreatefromjpeg($name);} //the follwoing segment of code checks the file type elseif ($type == 'image/gif') {$img = imagecreatefromgif($name);} elseif ($type == 'image/png') {$img = imagecreatefrompng($name);} elseif ($type == 'image/bmp') {$img = imagecreatefromwbmp($name);} else {$fail = 'incorrect file type, please upload either; JPG, BMP, GIF or PNG';} } //echo '<BR>size='.$size; //echo '<BR>type='.$type; //echo '<BR>name='.$name; //echo '<BR>tac='.$tac; if ($fail != '0'){} else { //echo '<BR>fail=PASS'; //TEMP marker to inform that fail=0 $iwidth = imagesx($img); //get image width $iheight = imagesy($img); //get image height //echo '<BR>Image dimentions:'.$iwidth.'x'.$iheight; //show dimentions before resize //Shrink image size if larger than 1000x1000 if($iwidth>$resize || $iheight>$resize){ $img_rezied = '1'; $tmp_iwidth= $resize; //set width of new size $tmp_iheight = $iheight * ($tmp_iwidth/$iwidth); //create height based on width maintaining aspect ratio $tmp_resized = imagecreatetruecolor($tmp_iwidth, $tmp_iheight); //create new images with resized dimentions imagecopyresampled($tmp_resized, $img, 0, 0, 0, 0, $tmp_iwidth,$tmp_iheight, $iwidth, $iheight); //resample image to new size $img = $tmp_resized; //set resampled image back to $img $iwidth=$tmp_iwidth; //reset the width $iheight=$tmp_iheight; // reset the height } imagealphablending($img, true); //turn on transparency on image $overlay = imagecreatefrompng($overlay); //create overlay image using user set file $owidth = imagesx($overlay); //get width of overlay image $oheight = imagesy($overlay); //get height of overlay image imagecopy($img, $overlay, $iwidth - $owidth, $iheight - $oheight, 0, 0, $owidth, $oheight); //apply overlay to image imagedestroy($overlay); //Get rid of temporary overlay file... $countfile = fopen($countpath, r); //open counter file $countnum = fread($countfile, filesize($countpath)); //get current counter integer fclose($countfile); //close counter file $newcountnum = $countnum + 1; //increment counter by one $path = 'uploads/'.str_pad($newcountnum,8,0,'STR_PAD_LEFT').'.jpg'; //create a new filename $webpath = $url.'/'.$path; //generate path to new photo if(!imagejpeg($img, $path, $quality)) { $fail = 'Unable to write a new JPEG. Contact the administrator.'; echo $fail; } else { $countfile = fopen($countpath, w); fwrite($countfile, $newcountnum); fclose($countfile); $success=1; } imagedestroy($img); //Get rid of our temporary file... //echo '<BR>Fail Status at end of image processing='.$fail; } if (!$fail=='0') { //failure during script so output UPLOAD FAILED echo '<font size="6">Upload Failed!</font>'; echo '<BR>'.$fail; echo '<BR>Try giving it another go...'; } else{ echo '<font size="6">Upload Sucess!</font>'; echo '<P>Your photo\'s has been uploaded to:<BR><A href='.$webpath.'>'.$webpath.'</A><br>you should see a preview of it below:</P>'; echo '<P><img src='.$webpath.' width=450></P>'; if ($img_resized = '1'){echo '<font size="1">Image resized to='.$iwidth.'x'.$iheight.'</font>';} //show new dimentions echo '<P>Now feel free to upload another if you\'d like...</P>'; } ?> </center> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/70470-size-_filesuploadsize-fault-in-php/#findComment-354374 Share on other sites More sharing options...
BlueSkyIS Posted September 24, 2007 Share Posted September 24, 2007 what is the value of upload_max_filesize in php.ini? Quote Link to comment https://forums.phpfreaks.com/topic/70470-size-_filesuploadsize-fault-in-php/#findComment-354378 Share on other sites More sharing options...
phillips321 Posted September 25, 2007 Author Share Posted September 25, 2007 BlueSkyIS, ur a legend! that was it, it was initially set as 2M, just changed that to 10M, pretty sure a user wont try to upload a 10MB image to my server. Once again can i say thanks for figuring this out for me, i thought it was an issue with my php code rather than my ini file. If your ever in southwest england i owe you a pint! Quote Link to comment https://forums.phpfreaks.com/topic/70470-size-_filesuploadsize-fault-in-php/#findComment-354475 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.