I'm having a bit of an issue that I can't quite figure out. I set the limit for MAX file size for file uploads to about 500 kb. - responds with an error msg if you exceed the file size. If you try to upload something slightly larger ... say 1 - 1.5M it responds with the error like it should however if you upload something much larger, say 5- 6M you get no error msg, it writes the filename to the db, but DOES NOT upload the file. Not sure what is allowing it to make it that far ??

function getExtension($str) {

         $i = strrpos($str,".");
         if (!$i) { return ""; } 
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;} 
   
 	  if(!isset($_FILES['photo']['name'])){
            $picture = '';
       }else{
		   
	   $ran = rand () ;
	   
	   $ran2 = $ran.".";
 	   $ext = getExtension ($_FILES['photo']['name']) ;	
	   if($picture=='' && $ext==''){
	   $picture2='NONE'; }
	   else
	   $picture2 = $ran2.$ext; }
	   
	    define ("MAX_SIZE","500");
  
 $errors=0;
 
 if($_SERVER["REQUEST_METHOD"] == "POST")
 { 
        $pic =$_FILES['photo']['name'];
 $uploadedfile = $_FILES['photo']['tmp_name'];

  if ($pic) 
  {
  $filename = stripslashes($_FILES['photo']['name']);
        $extension = getExtension($filename);
  $extension = strtolower($extension);
 if (($extension != "jpg") && ($extension != "jpeg") 
&& ($extension != "png") && ($extension != "gif")) 
  {
-------- Some error ---------
 $errors=1;
exit;
  }
 else
{
   $size=filesize($_FILES['photo']['tmp_name']);
 
if ($size > MAX_SIZE*1024)
{
-------  Some error --------
 $errors=1;
 exit;
}
 
if($extension=="jpg" || $extension=="jpeg" )
{
$uploadedfile = $_FILES['photo']['tmp_name'];
$src = @imagecreatefromjpeg($uploadedfile);
}
else if($extension=="png")
{
$uploadedfile = $_FILES['photo']['tmp_name'];
$src = @imagecreatefrompng($uploadedfile);
}
else 
{
$src = @imagecreatefromgif($uploadedfile);
}
 
list($width,$height)=getimagesize($uploadedfile);

$newwidth1=85;
$newheight1=($height/$width)*$newwidth1;
$tmp1=imagecreatetruecolor($newwidth1,$newheight1);

imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1, 
$width,$height);

$filename = "xpics/profiles/". $_FILES['photo']['']. $picture2;
$filename1 = "xpics/profiles/small/". $_FILES['photo']['']. $picture2;

copy($_FILES['photo']['tmp_name'], $filename);

imagejpeg($tmp1,$filename1,100);


imagedestroy($src);
imagedestroy($tmp1);

}
}
}
	}

hey icefrog... where is your move_uploaded_file() function? i cant seem to find it? it's responsible for uploading.

If you exceed the file size I don't want the script to even make it far enough to upload it ... I want it to die with an error like it is intended to do.
However, I did find this tidbit interesting ... Note: For IE to recognize jpg files the type must be pjpeg, for FireFox it must be jpeg.

ahhh ok sorry i thought your problem was about uploading... just hang in there... there will be someone veteran in PHP will solve your problem...

Nah, the upload is not the prob.

copy($_FILES['photo']['tmp_name'], $filename);

Copies the original image to a dir

imagejpeg($tmp1,$filename1,100);

Copies a resized jpeg to dir

I figured out that it seems to be okay until the file size starts to exceed 2 M ... after that filesize(); is bugging out and setting var $size to 0 allowing it to proceed. The strange thing is that it's not uploading the photo although I would think it would if var $size was set to 0.

My problem has been solved. My server host has a 2M limit on uploads. The filename would still write to the db because var $size set to 0 would allow the script to move past the MAX_SIZE in the script but the file would not upload because of the server restrictions.

good news... then you just solved your own problem yourself...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.