Only Specified Extension With Size Can Upload?

Discussion in 'PHP' started by sokaniwaal, Mar 22, 2011.

  1. #1
    Dear all i have a problem, how to do this with sql/php
    i have the following table structure. how to allow PHP upload file to upload only these extension having their respective size.
    table.jpg
     
    sokaniwaal, Mar 22, 2011 IP
  2. bledileka

    bledileka Peon

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $filetype = $_FILES['filefield']['type'];
    $q= ("select * from yourtablename where extension='$filetype' limit 1");
    $res= mysql_query($q) or die(mysql_error());
    if (mysql_num_rows($res)==0) {
    //it means file type not present in your table
    echo "File type not allowed !";
    } else {
    //this size is in byte, to use Kb or MB divide it ot 1024. example for mb : $mbfilesize = ($_FILES['filefield']['size']/1024)/1024;
    $filesize = $_FILES['filefield']['size'];
    while ($row=mysql_fetch_assoc($res)) { 
    $tblsize = $row['size'];
    }
    if ($filesize>$tblsize) { echo "Maximum file size allowed : ".$tblsize;} else { //continue upload }
    }
    
    
    Code (markup):
    hope this helps you get the idea!
     
    bledileka, Mar 24, 2011 IP
  3. sokaniwaal

    sokaniwaal Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you very much bledileka, problem solved :)
     
    sokaniwaal, Mar 24, 2011 IP