5

I'm having issues uploading a pdf to my server. The upload_max_filesize is 2M and the file(s) are more then that, around 4M. I found a post with a similar issue to mine here

$_FILE upload large file gives error 1 even though upload_max_size is bigger than the file size

What I can gather from php.net for the correct usage of ini_set commands is this, which I am currently using.

    ini_set('upload_max_filesize', 100000000);
    ini_set('post_max_size', 110000000);
    ini_set('memory_limit', 120000000);
    ini_set('max_input_time', 20);

But in the link I posted it seems they are using a different method (if they aren't just summarizing the correct code that is). But It seems my code isn't working as is either. I have <?php phpinfo(); ?> at the bottom of my page and it says the upload_max_filesize is still 2M. Am I using the correct syntax for ini_set? or is my issue with upload my pdfs something else?

My code handling the upload is

    //======================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==============

The output of the line 'print_r($_FILES['pdf']);' is

    Array ( [name] => takeoutmenu.pdf [type] => [tmp_name] => [error] => 1 [size] => 0 )
Community
  • 1
  • 1
d.lanza38
  • 2,525
  • 7
  • 30
  • 52
  • I'm of course just using those values for the php_ini just as an extreme so there was no chance of my uploads going over the limit, I would put a much lower value then what I posted. – d.lanza38 Nov 21 '11 at 17:46

1 Answers1

7

Some providers does not allow you change certain values in running time. Instead of this, try to either change it in the real php.ini file or use an .htaccess (For Apache web servers) where you can add your configuration. You can find more information in the PHP.net article about this subject: How to change configuration settings.

Based on your story, example .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>
0xd
  • 1,891
  • 12
  • 18
  • This isn't a provider its an in house server, but I personally don't have access to the httpd.conf file. I guess my only option is using the .htaccess file. There aren't really any examples on the page you linked to, I'm guessing the correct syntax I should use in the .htaccess file is "php_value upload_max_filesize '6M'" with AllowOverride All set? – d.lanza38 Nov 21 '11 at 18:11
  • Yes, your Apache directive for that host should have `AllowOverride All`. – 0xd Nov 21 '11 at 18:22
  • I used this as the contents of my .htaccess file - I don't know how to correctly put this in code brackets [code] Allowoverride All php_value upload_max_filesize 100000000 php_value post_max_size 110000000 php_value memory_limit 120000000 php_value max_input_time 20 [/code]I was guessing with the syntax I proposed was this correct or were you using my guess for the code you gave me? – d.lanza38 Nov 21 '11 at 18:32
  • The `Allowoverride All` directive should be in `httpd.conf` file. – 0xd Nov 21 '11 at 18:36
  • Ahh, so if that is not set in the httpd.conf file then my only option is to in some way contact out server administrator? And have him change the configuration in the real php.ini file, the httpd.conf file, or give me access to either of those? – d.lanza38 Nov 21 '11 at 18:41
  • I just tested the exact code you posted without the Allowoverride All and it worked. So it seems the allow override all is enabled in the httpd.conf, I just wanted to post the summarization above for anyone else looking at this. – d.lanza38 Nov 21 '11 at 18:43