dongyonglie5132 2012-09-14 19:17
浏览 32

PHP中的$ _FILES是否有预定义的上传限制?

Hi I'm fairly new to HTML, PHP, MySQL etc.. I am wondering if there is a predefined upload limit using $_FILES. I ask because when I try to upload 8 images of around 1.5 megabytes the code does not work but when I upload 10 images of around 60 kilobytes the code works fine. Here is my code and feel free to make any criticisms/comments about it:

</head>
<body>
<form action="test.php" method="POST" enctype="multipart/form-data" >
    <input type="file" name="image[]" multiple="multiple">
    <input type="submit" value="upload">
</form>    

<?php

include 'connect.php';

if(!empty($_FILES['image']['tmp_name'])){

    $allowed = array('jpg', 'gif', 'png', 'jpeg');
    $count = 0;
    foreach($_FILES['image']['name'] as $key => $name){

    $image_name = $name;
    $tmp = explode('.', $image_name);

    $image_extn = strtolower(end($tmp)); //can only reference file
    $image_temp = $_FILES['image']['tmp_name'][$count];
    $count = $count +1;

    if(in_array($image_extn, $allowed) === true){

        $image_path = 'images/' . md5($image_name) . '.' . $image_extn;

        move_uploaded_file($image_temp, $image_path);

        mysql_query("INSERT INTO store VALUES ('', '$image_name', '$image_path')") or die(mysql_error());

        $lastid = mysql_insert_id();
        $image_link = mysql_query("SELECT * FROM store WHERE id = $lastid");
        $image_link = mysql_fetch_assoc($image_link);
        $image_link = $image_link['image'];
        $uploaded[] = $image_link;

        }
        else{
            echo 'Incorrect file type. Allowed: ';
            echo implode(', ', $allowed);
            }
        }
    }        

    if(!empty($uploaded)){
        foreach($uploaded as  $new){
            echo "<a href = $new>$new</a><p></p>";

        }
    }
else{
        echo "Please select an image.";
    }
?>  
</body>
</html>
  • 写回答

4条回答 默认 最新

  • dongzouxigu12345 2012-09-14 19:19
    关注

    Here are the settings you want to change in php.ini:

    post_max_size This setting controls the size of an HTTP post, and it needs to be set larger than the upload_max_filesize setting.

    upload_max_filesize This value sets the maximum size of an upload file.

    Remember to restart your web server after making these changes.

    Ref:

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。