unable upload big files to server using php

2020-03-08 06:51发布

问题:

I can't load big files to server. The problem is in that file $_FILES["filename"]["tmp_name"] is empty if file a little more bigger then 2mb. I tried to change variables in php.ini

upload_max_filesize = 700M

post_max_size = 16M

but not working to. Also tried to add this variables to my .httaccess file - but 500 error appears.

Error code while uploading=1.
UPLOAD_ERR_INI_SIZE 

Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.

Here is my uppload.php page, please anwer what I doing wrong? Thanx!

<?php
    if(strlen($_FILES["filename"]["name"]))
    {
        $folder = "uploads/";
        echo $folder;
        $error = "";
        if($_FILES["filename"]["size"] > 1024*700*1024)
        {
            $error .= "<b><p class=ErrorMessage>Размер файла превышает 5Mb</p></b><br>";
            header("Location: upload.php?error=".$error, true, 303 );
        }
        if(!file_exists($folder.="hh/"))
        {
            if(!mkdir($folder, 0700))
                $error .= "<b><p class=ErrorMessage>Folder not created</p></b><br>";
        }
        //echo "<br>".$_FILES["filename"]["tmp_name"]."<br>";
        echo $folder.$_FILES["filename"]["name"]."<br>";
        echo $_FILES["filename"]["error"]."<br>";
        if(move_uploaded_file($_FILES["filename"]["tmp_name"], $folder.$_FILES["filename"]["name"]))
        {
            echo("Файл успешно загружен <br>");
            echo("Характеристики файла: <br>");
            echo("Имя файла: ");
            echo($_FILES["filename"]["name"]);
            echo("<br>Размер файла: ");
            echo($_FILES["filename"]["size"]);
            echo("<br>Каталог для загрузки: ");
            echo($folder.=$_FILES["filename"]["name"]);
            echo("<br>Тип файла: ");
            echo($_FILES["filename"]["type"]);
        } 
        else 
        {
            $error .= "<b><p class=ErrorMessage>Ошибка загрузки файла</p></b><br>";
        }
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Документ без названия</title>
</head>

<body>
        <?php 
            if(isset($_REQUEST["error"]))
            {
                echo $_REQUEST["error"];    
            }
        ?>
      <h2><p><b> Форма для загрузки файлов </b></p></h2>
      <form action="upload.php" method="post" enctype="multipart/form-data">
      <input type="file" name="filename" READONLY><br> 
      <input name="Upload" type="submit" value="Upload"><br>
      </form>


</body>

</html>

回答1:

check your php setting using phpinfo.php, if you have the right configuration. Then you will know exactly what to do.

And one more thing make sure the /tmp directory is writable for the current user.



回答2:

Maybe your php.ini is ignored. Try calling this from PHP.

ini_set('upload_max_filesize', '700M');
ini_set('post_max_size', '16M');

Or via .htaccess

php_value upload_max_filesize 700M
php_value post_max_size 16M


回答3:

try increasing these values in php.ini

memory_limit = 99M

max_execution_time = 300

upload_max_filesize = 20M

post_max_size = 24M



标签: php uploading