无法上传大小不超过10 MB的图片

时间:2015-04-13 12:53:07

标签: php

我正在尝试上传8mb的图片,但无法使用下面的脚本执行此操作? 。这是一个使用缩略图上传多个图像的脚本:

  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."' ";

}} }}}

1 个答案:

答案 0 :(得分:3)

转到xampp-&gt; php-&gt; php.ini。 在第922行找到类似这样的内容upload_max_filesize=20M将您的最大文件大小更改为您希望的大小。希望这有效。