php文件上传错误1 - 使用php_ini的正确方法是什么?

d.l*_*a38 4 php file-upload php-ini

我在将pdf上传到我的服务器时遇到问题.upload_max_filesize是2M,文件大于4M.我在这里发现了一个类似问题的帖子

即使upload_max_size大于文件大小,$ _FILE上传大文件也会出错1

我可以从php.net收集正确使用ini_set命令的是这个,我目前正在使用它.

    ini_set('upload_max_filesize', 100000000);
    ini_set('post_max_size', 110000000);
    ini_set('memory_limit', 120000000);
    ini_set('max_input_time', 20);
Run Code Online (Sandbox Code Playgroud)

但在我发布的链接中,似乎他们正在使用不同的方法(如果它们不只是总结正确的代码).但似乎我的代码也没有正常工作.我<?php phpinfo(); ?>在页面的底部,它说upload_max_filesize仍然是2M.我是否使用了ini_set的正确语法?或者我的问题是上传我的pdf别的东西?

处理上传的代码是

    //======================pdf upload=====================     
    if ($_POST['erasePDF'] == "Yes") //checking if erase box was checked and erasing if true
    {   
        if (file_exists($pdf))
        {
            unlink( $pdf );
            $pdf = "";
        }
    }   

    print_r($_FILES['pdf']);
    if (!empty($_FILES['pdf']['name'])) //checking if file upload box contains a value
    {
        $saveDirectoryPDF = 'pdfs/';            //name of folder to upload to
        $tempName = $_FILES['pdf']['tmp_name']; //getting the temp name on server
        $pdf = $_FILES['pdf']['name'];      //getting file name on users computer

        $test = array();
        $test = explode(".", $pdf);
        if((count($test) > 2) || ($test[1] != "pdf" && $test[1] != "doc" && $test[1] != "docx")){
            echo "invalid file";
        }else{

            $count = 1;
            do{
            $location = $saveDirectoryPDF . $count . $pdf;
            $count++; 
            }while(is_file($location));

            if (move_uploaded_file($tempName, $location))   //Moves the temp file on server
            {                                                           //to directory with real name
                $pdf = $location;
            } 
            else 
            {

                echo "hi";
                echo '<h1> There was an error while uploading the file.</h1>';
            }
        }
    }else{
        $pdf = "";
    }
    if(isset($_POST['link']) && $_POST['link'] != ""){
        $pdf = $_POST['link'];
    }
    //======================end of pdf upload==============
Run Code Online (Sandbox Code Playgroud)

行'print_r($ _ FILES ['pdf']);'的输出 是

    Array ( [name] => takeoutmenu.pdf [type] => [tmp_name] => [error] => 1 [size] => 0 )
Run Code Online (Sandbox Code Playgroud)

0xd*_*0xd 6

某些提供程序不允许您在运行时更改某些值.而不是这样,尝试在真正的php.ini文件中更改它,或使用.htaccess(对于Apache Web服务器),您可以在其中添加配置.您可以在PHP.net文章中找到有关此主题的更多信息:如何更改配置设置.

根据你的故事,例如.htaccess

<IfModule mod_php5.c>
php_value upload_max_filesize 100000000
php_value post_max_size 110000000
php_value memory_limit 120000000
php_value max_input_time 20
</IfModule>
Run Code Online (Sandbox Code Playgroud)