Search
Left Quote    I find that the harder I work, the more luck I seem to have.
- Thomas Jefferson    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: File Too Big Error
  This user is offline  fil2007
  Subject: "File Too Big Error" Posted: @ 6:23 am on Nov 23 2007   
Member #: 487
Rank: User - (1)
Since: 11/23/07
Posts: 1

Ok I basically copied the script to test out how things work before I modify it into my own liking.... so I have...

<?
if(isset($_POST ['submit'])) { //see if submit button is pressed.

//check if they decided to upload a pic:
if($_FILES['use rfile']['size'] > 1) {

$max_size = 100000;
$max_height = 300;
$max_width = 300;

$info = getimagesize($_ FILES['userfile ']['tmp_name']) ;
//check file-size (in bytes):
if(($_FILES['us erfile']['size' ] > $_POST['MAX_FIL E_SIZE']) || ($_FILES['userf ile']['size'] > $max_size)) {
die("<B R><BR> Error: Upload file size too large: (<b>" ; . $_FILES['userfi le']['size'] . "</b> ;). Must not exceed XX kb.");
}

//check the extension.
$array = explode(". ", $_FILES['userfi le']['name']);
$nr = count($array);
$ext = $array[$nr-1];< br /> if(($ext !="jpg&quo t;) && ($ext !="jpeg&qu ot;) && ($ext !="png&quo t;))
die("<B R><BR> Error: file extension un-recognized. Be sure your image follows the correct extension (.JPG or .PNG)");
//CHECK TYPE: (what the browser sent)
if(($_FILES['us erfile']['type' ] != "image/jpe g") && ($_FILES['userf ile']['type'] != "image/pjp eg") && ($_FILES['userf ile']['type'] != "image/png ")) {
die("< BR><BR> ;Error: Upload file type un-recognized. Only .JPG or .PNG images allowed.") ;
}

//DOUBLE CHECK TYPE: if image MIME type from GD getimagesize() -In case it was a FAKE!
if(($info['mime '] != "image/jpe g") && ($info['mime'] != "image/pjp eg") && ($info['mime'] != "image/png ")) {
die("< BR><BR> ;Error: Upload file type un-recognized. Only .JPG or .PNG images allowed.") ;
}

//check file size (length & width)
if(($info[0] > $max_width) || ($info[1] >$max_height )) {
die("<B R><BR> Error: Image size error (<b>" ; . $info[0] . "</b> ; x <b>" . $info[1] . "</b> ;). Must not exceed ". $max_height . " x ". $max_width .".") ;
}

//rename file, move it to location.
if(is_uploaded_ file($_FILES['u serfile']['tmp_ name'])) {

//get max number of images the user has uploaded
$m = mysql_query(&qu ot;SELECT max(user_images ) as `total_images` FROM `images` WHERE `user_id` = '".$_SESSI ON['user_id'].& quot;'");< br /> if(!$m) die('An Error Occurred.');
$result = mysql_fetch_obj ect($m);
if($result-> total_images <= 0) {
$image_number = 1;
} else {
$image_number = $result->tot al_images + 1;
} //end if

$filename = strtolower($_SE SSION['username ']) . $image_number;< br />
if(move_uploade d_file($_FILES[ 'userfile']['tm p_name'] , $_SERVER['DOCUM ENT_ROOT'].&quo t;/public_html/ articleart/&quo t;.$filename . '.' . $ext)) {
echo("File uploaded successfully.&q uot;);
} else {
echo("An error occurred while uploading." ;);
}//end upload
} //end is_uploaded_fil e
}

} else { //display form ?>

<form enctype="m ultipart/form-d ata" action="&l t;? $_SERVER['PHP_S ELF']; ?>" method="po st" name="uplo adImage" />
<input type="hidd en" MAX_UPLOAD_SIZE = "10000&quo t; />
<input type="file " name="user file" size="35&q uot; />
<input type="subm it" name="subm it" value="Upl oad Image">

<? } //end else ?>


page loads and everything is great but when i load a jpg image, no matter if its 1kb i get "Error: Upload file size too large: (1165). Must not exceed XX kb".

Any help would be greatly appreciated. Amazing tutorial by the way :-)


    Viewed: 5,122 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: File Too Big Error" Posted: @ 5:45 pm on Nov 23 2007    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

You could always increase the value of the $max_size variable for testing




-bs0d | AllSyntax.com

    Viewed: 5,098 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank