Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14

Thread: php.ini error

  1. #1
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    912
    Thanks
    76
    Thanked 28 Times in 28 Posts

    php.ini error

    Hi, I was practicing working on a file upload form and decided to change the post_max_size and upload_max_filesize values to 10M each.

    I also wanted to check for my error reporting also because I wasn't too sure if I had them on. Since doing so, when I check the phpinfo() file straight from the /localhost/ page, the url looks like this: http://localhost/?phpinfo=1. Also, it isn't changing the file and post values, they are still at default, even after restarting WAMP.

    It's weird because when I run the phpinfo() function within my script, it displays a 1 right at the bottom. I thought maybe it could be hardcoded into the php.ini file by mistake. When I check phpinfo() directly from the /localhost/ screen, although it takes 1 within the url, it doesn't display the 1 right at the bottom.

    I didn't know whether it was hardcoded into my actual file im working on or whether it was in the php.ini, so I ran a die() function straight after the phpinfo() call in my script and it still displayed the 1, so I know for definite it is in my php.ini file.

    What I needed to know is if you change a comment line, does it affect anything. I wouldn't have thought so but I've just sifted through my php.ini several times and can't see anything out of place on the execution lines.

    Edit: Just opened up the php.ini straight from my WAMP icon and changed the values to 10M and now they have suddenly changed? That '1' is still showing up when I run phpinfo() from my script. Any ideas what it could mean?

    Regards,

    LC.
    Last edited by LearningCoder; 12-31-2012 at 04:15 AM.

  • #2
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    Please can I see the error?

  • #3
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    912
    Thanks
    76
    Thanked 28 Times in 28 Posts
    It's not an error as such, it just shows a '1' right at the bottom of phpinfo(), but only when I run it from my script. When I run it from the localhost screen, it doesn't show the 1.

    Kind regards,

    Lc.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Post the script you are using for phpinfo.
    My suspicion is you are using echo phpinfo(); which results in a output for the phpinfo goverened (INFO_ALL by default), and then prints the result of it which is true (and always should be). So in other words, phpinfo dumps directly to the output and returns a result, so if you print the function call you'll end up with the output and then the result of the function.

  • #5
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    912
    Thanks
    76
    Thanked 28 Times in 28 Posts
    That is correct, I am using:
    PHP Code:
    echo phpinfo(); 
    Here is the script:
    PHP Code:
    <?php
    echo phpinfo();die();
    define('MAX_FILE_SIZE',10485760);

    $error_types = array();

    $error_types[1] = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
    $error_types[2] = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';
    $error_types[3] = 'The uploaded file was only partially uploaded.';
    $error_types[4] = 'No file was uploaded.';
    $error_types[6] = 'Missing a temporary folder.';
    $error_types[7] = 'Failed to write file to disk.';
    $error_types[8] = 'A PHP extension stopped the file upload.';

    if(isset(
    $_FILES['the_file'])){
        
    /*
        $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
        $file = $_FILES['the_file']['tmp_name'];
        $filetype = finfo_file($finfo,$file);
        */
        
        
    echo "<pre>";
        
    print_r($_FILES);
        echo 
    "</pre>";
        
        if(
    $_FILES['the_file']['error'] != 0)
        {
            echo 
    $error_types[$_FILES['the_file']['error']];
        }
        
    }

    ?>
    <!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>
        <title>HTML Template</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <script type="text/javascript" src="jquery-1.8.3.js"></script>
    <style type="text/css">

    </style>
    <script>

    </script>

    </head>

    <body>

    <form action="" method="post" enctype="multipart/form-data">
             <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE?>">
        File:<input type="file" name="the_file" /><br />
             <input type="submit" value="Upload File" />
    </form>

    </body>
    </html>
    Kind regards,

    LC.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Yep, that's no problem then. Remove the echo, phpinfo() automatically writes to output.

  • Users who have thanked Fou-Lu for this post:

    LearningCoder (12-31-2012)

  • #7
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    912
    Thanks
    76
    Thanked 28 Times in 28 Posts
    Thank you very much. I spent ages searching for that hardcoded 1 :S

    Kind regards,

    LC.

  • #8
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    912
    Thanks
    76
    Thanked 28 Times in 28 Posts
    Just having some issues with the upload. As you can see from my above code, I define a constant which is used to set the hidden field in the form, and it will also be used later in the script to be compared with the ['size'] array element.

    When I upload a file which is larger than the constant size, it doesn't execute the if statement which starts the form processing, it just prints the form again.

    Here is my code:
    PHP Code:
    <?php
    define
    ('MAX_FILE_SIZE',10485760);

    $error_types = array();

    $error_types[1] = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
    $error_types[2] = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';
    $error_types[3] = 'The uploaded file was only partially uploaded.';
    $error_types[4] = 'No file was uploaded.';
    $error_types[6] = 'Missing a temporary folder.';
    $error_types[7] = 'Failed to write file to disk.';
    $error_types[8] = 'A PHP extension stopped the file upload.';

    if(isset(
    $_POST['submit'])){
        
    /*
        $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
        $file = $_FILES['the_file']['tmp_name'];
        $filetype = finfo_file($finfo,$file);
        */
        
    echo "aiiiyo";
        echo 
    "<pre>";
        
    print_r($_FILES);
        echo 
    "</pre>";
        
        if(
    $_FILES['the_file']['error'] != 0)
        {
            echo 
    $error_types[$_FILES['the_file']['error']];
        }
        
    }

    ?>
    <!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>
        <title>HTML Template</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <script type="text/javascript" src="jquery-1.8.3.js"></script>
    <style type="text/css">

    </style>
    <script>

    </script>

    </head>

    <body>

    <form action="" method="post" enctype="multipart/form-data">
             <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE?>">
        File:<input type="file" name="the_file" /><br />
             <input type="submit" name="submit" value="Upload File" />
    </form>

    </body>
    </html>
    My post_max_size and upload_max_filesize directives are both set at 10M. I know the if statement isn't executing because my print_r($_FILES) statement is not printing anything.

    What I want to know is:

    1. Why the code doesn't execute when it's a larger size than the php.ini directives or the constant value.

    2. php obviously created 2 error constants to deal with files which are larger in size than the MAX_FILE_SIZE html form value and also the upload_max_filesize directive, so why doesn't my code execute at all.

    3. How can I make it execute when the file size is greater?

    Kind regards,

    LC.
    Last edited by LearningCoder; 12-31-2012 at 11:46 PM.

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Works fine for me.
    Make sure you're not using IE and if you are to actually click the submit button. I can't test that since my IE refuses to connect to localhost, and I refuse to do anything to fix it.

  • #10
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    912
    Thanks
    76
    Thanked 28 Times in 28 Posts
    Heh, nah I'm using FF and was clicking the submit button already.

    So when you used the code, it printed the error?

    Did you try and upload a file greater than the MAX_FILE_SIZE constant?

    Kind regards,

    LC.
    Last edited by LearningCoder; 01-01-2013 at 12:38 AM.

  • #11
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    912
    Thanks
    76
    Thanked 28 Times in 28 Posts
    Could it be something to do with post_max_size being at 10M? Because the file is over 10M is it being affected by the post_max_size directive because when it's higher than 10M it is not executing the if statement which leads me to think that no post data is being sent at all?

    EDIT: Just set the post_max_size to 20M in php.ini and now my if statement executes and shows this error: The uploaded file exceeds the upload_max_filesize directive in php.ini. . That was with a 12mb file size. My upload_max_filesize is still at 10M.

    How do I get the error to show which deals with the MAX_FILE_SIZE?

    Kind regards,

    LC.
    Last edited by LearningCoder; 01-01-2013 at 12:55 AM.

  • #12
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Yeah I get the proper error. If I set it low, I trigger a form max_size error, and if I set it high and leave the ini at 2MB I get an ini max size error.
    It would take more testing, but it looks to me that 2MB doesn't actually equate to 1024*1024*2 despite the documentation specifying that it does. So don't make them too close together.

  • #13
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    912
    Thanks
    76
    Thanked 28 Times in 28 Posts
    So for example, rather than setting my constant to the exact calculation of 10MB in bytes like : 10485760, I should set it to something like: 10000000??

    Of course I will carry on testing, setting the directives to different values and testing the result.

    Thanks for your reply.

    Kind regards,

    Lc.

  • #14
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Yeah, I'm not sure where the cutoff is. I know both 2000000 and 1999999 are good on a 2M max, 2097151 is still triggering ini, as is 2097000. So I'm not sure what PHP is doing with the 2M in comparison to what it *should* be doing.
    Also, you can probably verify it easier by using an explicit byte number in the ini. Set that as 2097152 (or whatever you want for 10x that for example), then use the form setting to change it up or down a byte to see what it does. My suspicion is that its simply a conversion issue to the 2MB, but I don't know where it is since 2000001 is still considered a form max.
    This could potentially be an issue with the browsers as well. I don't know at which point the form max size is applied. To me, I would assume its at the point of the Server, but perhaps it is on the client given that it is an HTML input.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •