SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    sydney
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MAX_FILE_SIZE & error handling

    Hi there

    I'm working with file uploads and PHP. My upload form has a hidden input
    with a MAX_FILE_SIZE name.

    I'm curious how to error handle when this lmit is exceeded. What is the best
    way to deal with such errors?

    At the moment, the rest of my upload script runs which attempts to move the
    uploaded file to a particular directory and to write the path into a MySQL
    database. Of course the file is not actually uploaded so my script is
    "spiining its wheels" so to speak.

    Is there a best practice for dealing with errors generated by MAX_FILE_SIZE?

    Many thanks

    Bongoman

  2. #2
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if ($_FILES['filename']['size'] > $MAX_FILE_SIZE) {
    die (
    "The file is too big");

    Or you can create some other trigger function to display the error. This is just a basic example

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    Milano
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Avoid putting MAX_FILE_SIZE in a hidden input since it may be manipulated by malicious users. It's by far better to define a constant.

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    like
    PHP Code:
    $max_file_size '1024';
    if ( 
    $_FILES['filename']['size'] > $max_file_size ) die ( "The file is too big" ); 
    cheers


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
  •