SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    File upload help (max file size)

    Hope someone can help with this. Have a file upload script that all seemed to be working fine, using the PHP component that resizes images (forget it's name).

    So it checks the file name is unique, checks it's a jpg, gif, bmp or photoshop file as requires, and has a max file size line to limit it's size.

    However, it seems that with any file over around 2MB, it's not uploading, and we're getting the error about it not being a jpg or gif.

    The line in the upload page is :

    Code:
    <input name="uploadFile" type="file" size="55">
    <input type="hidden" name="MAX_FILE_SIZE" value="80000" />
    It did have a default value of 25000 but I changed it to 80000, but still the same problem.

    Some code from the validation page :

    Code:
    $ValidationFailed = false;
    
    if (($_FILES["uploadFile"]["type"] == "image/gif") 
    || ($_FILES["uploadFile"]["type"] == "image/pjpeg")
    || ($_FILES["uploadFile"]["type"] == "image/tif")
    || ($_FILES["uploadFile"]["type"] == "image/png")
    || ($_FILES["uploadFile"]["type"] == "image/photoshop")
    || ($_FILES["uploadFile"]["type"] == "image/bmp")) 
      { 
      if ($_FILES["uploadFile"]["error"] > 0) 
        { 
         $ValidationFailed = true; 
         $FTGvalid_file_errmsg = "Error: " . $_FILES["file"]["error"]; 
         $ErrorList .= $FTGvalid_file_errmsg . '<br/>'; 
        } 
      } 
    else 
      { 
      $ValidationFailed = true; 
      $FTGvalid_file_errmsg = "Please select a valid image file type. The library supports .jpg, .gif, and .png files."; 
      $ErrorList .= $FTGvalid_file_errmsg . '<br/>'; 
      }
      
    if (!empty($_FILES['uploadFile']['name']) && file_exists("Photos/" . $_FILES["uploadFile"]["name"]) && is_file('Photos/' . $_FILES['uploadFile']['name'])) 
    { 
      $ValidationFailed = true; 
      $FTGvalid_file_errmsg = "This file has already been uploaded. If you are sure it's a new photo please rename it before uploading to the library."; 
      $ErrorList .= $FTGvalid_file_errmsg . '<br/>'; 
        }
    Any ideas?

  2. #2
    SitePoint Wizard Nikolas's Avatar
    Join Date
    Feb 2005
    Location
    Greece
    Posts
    1,222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put this in the beginning of your script :

    PHP Code:
    ini_set('upload_max_filesize''3M'); 

  3. #3
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No joy, I'm afraid - sussed out to change the max file upload size in the php.ini file, but didn't work, and have been trying what you suggested above in the file with the upload script, but that's not working either.

    Added in :

    Code:
    print_r($_FILES["uploadFile"]["type"]);
    to have a look, and it's drawing a blank with files > 2MB still, and correctly displaying image/pjpeg for images < 2MB.

  4. #4
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just having a look at this again this morning, and added in a

    Code:
    phpinfo ();
    Which is correctly listing the max file upload size as 8M, so I'm pretty stuck now.

    It's still bringing up my 'Please select a valid image file type. The library supports .jpg, .gif, and .png files.'

    So it's not OK for jpgs >2M, even tho' the max file size is set to 8M, and it is fine for jpgs < 2M.

    Any more ideas.....?

  5. #5
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just spotted that the

    upload_max_filesize is still showing as 2M in phpinfo(), even tho' I've changed it to 8M in the php.ini file, and added

    Code:
    <?php
    ini_set('upload_max_filesize', '8M'); 
    ?>
    to the top of the page with the upload script.

    I changed the post_max_size to 9M in the php.ini, but it's still showing as 8M in the phpinfo() too.

    What could be stopping this from taking effect, if it's changed in the php.ini file, and forced using ini_set?

  6. #6
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [resolved]

    OK - stop the clock.

    Stopping and restarting the Apache server did the trick.


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
  •