文件上传在PHP中无法正常工作

时间:2017-06-09 11:06:39

标签: php file-upload

我在PHP中创建了一个文件上传。最大文件大小为5MB。我试图上传一个39 MB的文件。

文件上传对于5MB或小于5MB的所有文件都工作正常,甚至可以正常工作30 MB文件并返回ERROR:MAX文件大小限制超过。但只有在这种情况下,39MB才会返回以下错误。

我低于错误。 enter image description here

    **action.php**

         <form class="w3-container " action='file_upload.php' method='post' enctype="multipart/form-data" name="form"  id="form-e" role="form">
            <DIV id="file_name_div">  
            <label  for="file_name">Enter file name: </label><br>                       
            <input data-validation="filename" autocomplete="off" style="width:30%" class="w3-input w3-border w3-light-grey " type="text" name='file_name' id='file_name' autofocus /> 
<label  for="Role">Enter Role: </label><br>                       
            <input data-validation="role" style="width:30%" class="w3-input w3-border w3-light-grey " type="text" name='role' id='role' autofocus /> 
            </DIV>
            <br>  
            <button type="reset" class="btn btn-info btn-md w3-blue"><span class="glyphicon glyphicon-refresh"></span> Reset</button> 
        </form>

****file_upload.php****

        <?php
        session_start();
        include_once 'config.php';
        $message  = '';
        $fileName = $_POST['file_name']; //LINE NO 6
        $role     = $_POST['role']; #role code //LINE NO 7
        $dir= "files/$role/"; #uploading file to selected role
        foreach ($_FILES as $filename => $filearray) {
        if (is_uploaded_file($filearray['tmp_name'])) {

            $fileLogicalName = $filearray['name'];

            $fileSize = (int) ($filearray['size'] / 1024);

            $filePhysicalName = pathinfo("$fileLogicalName"); //Return complete file name with extension 

            $filePhysicalName['filename']; //The arrray of pathinfo return only file name without extension


            if ($fileSize <= 5120) // 5mb/1024
                {
//file upload code
                }
    }
    }
        ?>

1 个答案:

答案 0 :(得分:0)

尝试在文件限制中添加更多大小

ini_set('memory_limit','1028M');
ini_set('upload_max_filesize','1028M');
ini_set('post_max_siz','1028M');