doujie4344 2015-07-11 06:44
浏览 61

PHP中的文件上传大小甚至不是2MB

I want to upload image to the some folder but only image having size less than 20Kb are only being uploaded. I am not able to upload even file upto 2Mb as it is by default in php.ini file. I have changes the values for

upload_max_filesize=40M 
post_max_size=40M

I dont know what the problem is. I am using a Xammp server

<?php
include_once("connect.php"); 
session_start();
if(isset($_POST['subm']))
{
  extract($_POST);
  $_SESSION['artsubmit_error'] = "";
  $title1 =  $_POST['title'];
  $intro1 = $_POST['intro'];
  $descr1 = $_POST['descr'];

 $imgname= $_FILES["file"]["name"];
 $artid = "".$_SESSION['logged_user_email']."";

 $allowedExts = array("GIF", "JPEG", "JPG", "PNG");
 $temp = explode(".", $_FILES["file"]["name"]);
 $extension = end($temp);
 echo "$extension";
 if ((($_FILES["file"]["type"] == "image/gif")
 || ($_FILES["file"]["type"] == "image/jpeg")
 || ($_FILES["file"]["type"] == "image/jpg")
 || ($_FILES["file"]["type"] == "image/pjpeg")
 || ($_FILES["file"]["type"] == "image/x-png")
 || ($_FILES["file"]["type"] == "image/png"))
 && ($_FILES["file"]["size"] < 10000000)
 && in_array($extension, $allowedExts))
 {

    if(!is_dir("Article/".$artid.""))
     {  mkdir("Article/".$artid.""); }
     mkdir("Article/".$artid."/".$title1.""); 
     move_uploaded_file($_FILES["file"]["tmp_name"],"article/".$artid."/".$title1."/".$_FILES["file"]["name"]."");
  }
  else
  {
    print "<br> ".$_FILES["file"]["type"]."";print "<br>";
    print "<h2>Invalid image. File should be less than 2MB <h2>";
    header( "refresh: 2;url=articlestore.php" ); exit;
  }

  $parag = nl2br("$descr1");
  $query = "insert into article values('','$userid','$title1','$intro1','$parag','$imgname',NOW())";
  mysql_query($query) or die("unsucessfull");

  $_SESSION['artsubmit_error'] = "Article submitted. Post another";
  header("Location: articlestore.php" );exit; 
  } 
  ?>
  • 写回答

1条回答 默认 最新

  • duanmin0941 2015-07-11 07:04
    关注

    the problem is solved. I just changed

    $allowedExts = array("gif", "jpeg", "jpg", "png");
    

    To

    $allowedExts = array("gif", "jpeg", "jpg", "png","GIF","JPEG","JPG","PNG");
    

    now its working fine for all type of images and even size greater than 2MB

    评论

报告相同问题?

悬赏问题

  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀