简体   繁体   中英

Unable to upload image of size up to 10 mb

I am trying to upload image of 8mb but not able to do this with the script below? . This is a script to upload multiple images with thumbnails :

  define ("MAX_SIZE","2000");
    define ("WIDTH","150");
    define ("HEIGHT","100");
    function make_thumb($img_name,$filename,$new_w,$new_h)
    {

$ext=getExtension($img_name);
if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
$src_img=imagecreatefromjpeg($img_name);

if(!strcmp("png",$ext))
$src_img=imagecreatefrompng($img_name);

$old_x=imageSX($src_img);
$old_y=imageSY($src_img);


$ratio1=$old_x/$new_w;
$ratio2=$old_y/$new_h;
if($ratio1>$ratio2) {
$thumb_w=$new_w;
$thumb_h=$old_y/$ratio1;
}
else {
$thumb_h=$new_h;
$thumb_w=$old_x/$ratio2;
}

$dst_img=ImageCreateTrueColor(300,256);
// resize the big image to the new created one
imagecopyresampled($dst_img,$src_img,0,0,0,0,300,256,$old_x,$old_y);

if(!strcmp("png",$ext))
imagepng($dst_img,$filename);
else
imagejpeg($dst_img,$filename);

imagedestroy($dst_img);
imagedestroy($src_img);
}

function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

/*-------------------image------*/
if(isset($img['image']['name'][0])){
if($img['image']['name'][0]!=''){
$errors=0;
for($i=0;$i<count($_FILES['image']['name']);$i++){

$image=$_FILES['image']['name'][$i];
if ($image)
{

$filename = stripslashes($_FILES['image']['name'][$i]);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png"))
{
echo '<h1>Unknown extension!</h1>';
$errors=1;
}
else
{
$size=getimagesize($_FILES['image']['tmp_name'][$i]);
$sizekb=filesize($_FILES['image']['tmp_name'][$i]);

if ($sizekb > MAX_SIZE*1024)
{
echo '<h1>You have exceeded the size limit!</h1>';
$errors=1;
}


$image_name=uniqid().'.'.$extension;


$newname="team_images/".$image_name;

$copied = copy($_FILES['image']['tmp_name'][$i], $newname);
if (!$copied)
{
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}
else
{
$thumb_name='team_images/thumbs/thumb_'.$image_name;

$thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT);
$sql .= ",IMAGE_PATH='".$image_name."' ";

}} }}}

GO to xampp->php->php.ini. There on line 922 find something like this upload_max_filesize=20M Change your max file size to what you wish to. Hope this works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM