SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Working on it... Contrid's Avatar
    Join Date
    Apr 2006
    Location
    Online
    Posts
    955
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    upload_max_filesize and ini_set question

    Hi there,

    I have a question here about something I haven't been sure about.

    The php.ini configuration file has a setting named "upload_max_filesize" which tells PHP/Apache to not allow file uploads above that size.

    When does this take effect?
    When the $_POST headers are received, or when the move_uploaded_file() function is executed?

    I'm assuming the first...though I'm not 100% sure.
    Please post your comments regarding this. I'm a bit confused.
    And so I got lost in code...completely asphyxiated by it...

    Premium WordPress plugins - Tribulant Software

  2. #2
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my mobile portal
    ghiris.ro

  3. #3
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There does seem to be a lot of confusion from people on this. I've even seen some people erroneously stating that your file isn't uploaded until you use move_uploaded_file on it - this just simply is not true!

    Your script won't even begin to execute until the file has been fully uploaded to your server. This right away should answer your question regarding when "upload_max_filesize" is applied - the file is already uploaded long before you have the opportunity to use move_uploaded_file. If you doubt it, upload a file that exceeds this setting, then check $_FILES['userfile']['error'] before you execute move_uploaded_file. You'll see the error UPLOAD_ERR_INI_SIZE (integer value 1), and the file won't even be available to you to run move_uploaded_file on.
    PHP questions? RTFM
    MySQL questions? RTFM

  4. #4
    Working on it... Contrid's Avatar
    Join Date
    Apr 2006
    Location
    Online
    Posts
    955
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    @kromey

    Thanks for the response.
    So what about ini_set() ?
    Should it be placed on the script with the FORM or in the script that receives $_FILES ?
    And so I got lost in code...completely asphyxiated by it...

    Premium WordPress plugins - Tribulant Software

  5. #5
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using ini_set on upload_max_filesize will not have any effect, since changes made to the .ini settings through this function are valid only for the execution of the current script. Since file upload happens after your form script has finished executing but before your processing script begins, it has absolutely no effect on your file size limit.

    In fact, PHP won't even let you set this directive via ini_set. See http://us.php.net/manual/en/ini.php#ini.list It can only be changed via php.ini or (if you're using Apache) in .htaccess or httpd.conf.
    PHP questions? RTFM
    MySQL questions? RTFM

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,871
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The maximum file size set by default is usually as big as should be used for uploading files via the extremely inefficient method that the method provides. If your files are getting anywhere near that big or are even bigger than that then you should be using the ftp extension to PHP to do the file uploads since that is designed for file transfers and does so as efficiently as possible where the simpler method is not efficient and can tie up all the resources on the server for a long period if you try uploading a larger file.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

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