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);
}
}
}
}