SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to limit files size when uploading

    Sir,

    I am uploadding a file .And i want to limit the size of uploading files if the file exceed the size i want to through error cannot upload how can i do that

    Thanks
    Where there is a will there is a way
    ArunKumar

  2. #2
    SitePoint Member magistudios's Avatar
    Join Date
    Feb 2005
    Location
    Victoria, BC
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey arunkumar,

    Here is a link that gives you advide on what you are asking:

    http://www.phpbuilder.com/tips/item.php?id=526

    Hope this helps.
    Jay Neill
    Chief Strategy Officer
    Magi Studios
    www.magistudios.com

  3. #3
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi thankyou for that,

    here they are given

    <input type=hidden name=MAX_FILE_SIZE value=1024> <input type=file name=userfile>

    this is two tag .Here the hidden is not related to file size it is diiferent tag right how it be possiblr for me to check that file excess the size
    Where there is a will there is a way
    ArunKumar

  4. #4
    PEACE WILL WIN abalfazl's Avatar
    Join Date
    Feb 2005
    Location
    Beyond the seas there is a town
    Posts
    711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  5. #5
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry for that i got it ok thank you alll
    Where there is a will there is a way
    ArunKumar

  6. #6
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can i limit the image width and height of the image that i am uploading
    Where there is a will there is a way
    ArunKumar

  7. #7
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sir,

    is there is any way so that i upload a file with certasin width and height
    Where there is a will there is a way
    ArunKumar

  8. #8
    SitePoint Addict
    Join Date
    Sep 2004
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Use getimagesize().
    Returns an array with 4 elements. Index 0 contains the width of the image in pixels. Index 1 contains the height. Index 2 is a flag indicating the type of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM. These values correspond to the IMAGETYPE constants that were added in PHP 4.3.0. Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.

    You cand use it like this

    $size = getimagesize("your_image_name");
    $width = $size['0'];
    $height = size['1'];

    Then you can verify these against your values

    if ($width != some value) {
    //error message
    }
    elseif ($height != some other value) {
    //error message
    }


    Hope this helps.

  9. #9
    PEACE WILL WIN abalfazl's Avatar
    Join Date
    Feb 2005
    Location
    Beyond the seas there is a town
    Posts
    711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hello MY firend

    Hello my firend

    You can use something called a gd library (an extension to PHP) to crop/resize images, thus limiting the size.




    PHP Code:

    $filename 
    "mypic.jpg"
    $im imagecreatefromjpeg($filename); // change function according to picturetype (jpeg,gif,png etc..) 
    $imx imagesx($im); // get images size 
    $imy imagesy($im), 
    $nsx 150// new image size 
    $nsy 150
    $new_image imagecreatetruecolor($nsx,$nsy); // new size 
    // The imagecopyresized function is a bit difficult, read the manual on how to use it, and to understand my code 
    // This crops a part 150x150 in the middle of the picture 
    $newx round(($imgx-$nsx) / 2); // get the crop starting point 
    $newy round(($imgy-$nsy) / 2); 
    $newW $newx $nsx// get X crop size 
    $newH $newy $nsy// get Y crop size 
    $copied imagecopyresized($new_image,$im,0,0,$newx,$newy,$nsx,$nsy,$newW,$newH); 
    imagejpeg($new_image"small_".$filename); // print to file 
    imagedestroy($im); // free memory 
    imagedestroy($new_image); 
    It may not work correctly, don't quite remeber all the gd functions, but it gives you the basic idea of how it works


    GOOD LUCK


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
  •