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

时间:2015-07-11 06:44:21

标签: php file-upload

我想将图片上传到某个文件夹,但只会上传大小小于20Kb的图片。我无法上传甚至是2Mb的文件,因为它在php.ini文件中是默认的。我更改了

的值
upload_max_filesize=40M 
post_max_size=40M

我不知道问题是什么。我正在使用Xammp服务器

<?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 个答案:

答案 0 :(得分:0)

问题解决了。我刚刚改变了

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

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

现在它适用于所有类型的图像,甚至大小超过2MB