简体   繁体   English

在php.ini上更改upload_max_filesize后,PHP文件的上传大小受到限制

[英]PHP file upload size is limited after changing upload_max_filesize on php.ini

I am creating an online gallery with upload function. 我正在创建一个具有上传功能的在线画廊。 I use PHP to upload the images and store it in mysql database. 我使用PHP上传图像并将其存储在mysql数据库中。 It seems that it does not allow me to upload file size more than 64KB. 似乎不允许我上传超过64KB的文件。

The following is my HTML code 以下是我的HTML代码

<form action="upload.php" method="POST" enctype="multipart/form-data">
    <label>File: </label>
    <input type="file" name="image" />
    <input type="submit" value="upload" name="submit"/>
</form>

upload.php code upload.php代码

<?php

//file properties
if(isset($_POST['submit']))
{

    if(getimagesize($_FILES['image']['tmp_name']) == FALSE)
    {
        echo "Please select an image";
    }
    else
    {
        $image = addslashes($_FILES['image']['tmp_name']);
        $name = addslashes($_FILES['image']['name']);
        $image = file_get_contents($image);
        $image = base64_encode($image);
        saveimage($name,$image);
    }
}
displayimage();
function saveimage($name,$image){
        $con=mysql_connect("localhost","root","admin");
        mysql_select_db("brandon",$con);
        $qry = "insert into store(name,image) values('$name','$image')";
        $result = mysql_query($qry,$con);
        if($result){
            echo "<br/> Image uploaded";
        }else{
            echo "<br/> Image not uploaded";
        }
    }
//display image
function displayimage()
{
    $con=mysql_connect("localhost","root","admin");
    mysql_select_db("brandon",$con);
    $qry="select * from store";
    $result=mysql_query($qry,$con);
    while($row = mysql_fetch_array($result))
    {
        echo '<img height="300" width="300" src="data:image;base64,'.$row[2].' "> ';
    }
    mysql_close($con);
}

on my database I have setup a table with 3 columns(id,name,image). 在我的数据库上,我设置了一个包含3列(id,name,image)的表。 ID is auto increment and primary. ID是自动递增且是主要的。 Name is TEXT and image is LONGBLOB. 名称为TEXT,图像为LONGBLOB。

I am using PHPstorm with PHP version 5.6.3. 我将PHPstorm与PHP版本5.6.3一起使用。 Xampp version is 3.2.1. Xampp版本是3.2.1。 Others suggest to increase the upload_max_limit on php.ini but it is not working for me. 其他人建议增加php.ini上的upload_max_limit ,但对我不起作用。 I have changed it to as following 我将其更改为以下内容

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize=128M

; Maximum size of POST data that PHP will accept.
post_max_size=128M

With the max_memory set to 128M and 60s timeout. 将max_memory设置为128M,超时为60s。

It all goes smooth if I upload a small image file but if I upload a large image file, it goes as following 如果我上传一个小图像文件,一切顺利,但是如果我上传一个大图像文件,它如下

  • takes me to a blank page(echo function not executed but displays previously uploaded images) 带我到空白页(未执行回显功能,但显示以前上传的图像)
  • when I try to access another php file, it loads endlessly.(it says waiting for localhost on the bottom left corner of google chrome) 当我尝试访问另一个php文件时,它会不断加载。(它表示等待google chrome左下角的localhost)
  • when I try to access another php file, it shows '502 bad gateway' 当我尝试访问另一个PHP文件时,它显示“ 502错误的网关”

Please help and thanks in advance 请帮助并提前感谢

Edit 1: The debugger, apache and mysql error logs shows no error. 编辑1:调试器,apache和mysql错误日志显示没有错误。 I restarted XAMPP, PHPStorm and my Chrome browser in order to get it to a working state again (which allows me to upload small image files and execute php files instead of endless loading and 502 bad gateway) 我重新启动了XAMPP,PHPStorm和我的Chrome浏览器,以使其再次进入工作状态(这使我可以上传小图像文件并执行php文件,而不是无休止的加载和502错误的网关)

Edit 2: Solved! 编辑2:解决了! I tried launching it from localhost instead of the autolaunch from PHPStorm. 我尝试从本地主机启动它,而不是从PHPStorm启动。 It works just fine. 它工作正常。

After changing the php.ini file did you restart Xampp? 更改php.ini文件后,是否重新启动了Xampp? It won't take affect until that happens. 直到那件事发生,它才会生效。 Also, check your PHP and Apache error logs regarding the bad gateway error, that might give you some more detail as to what's going on. 另外,请检查有关网关错误的PHP和Apache错误日志,这可能会给您更多有关发生的情况的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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