File type validation with Php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • underground
    New Member
    • Sep 2006
    • 41

    File type validation with Php

    I have a query I use to insert data and text into my DB. The script provides the validation for the file size not type is assigned, how do I add the file type validation to this script. Could someone point to some material that will help me out of the jam?

    [PHP]
    // Connect to database

    $errmsg = "";
    if (! @mysql_connect( "#","#","#" )) {
    $errmsg = "Cannot connect to database";
    }
    @mysql_select_d b("000000");

    // First run ONLY - need to create table by uncommenting this
    // Or with silent @ we can let it fail every sunsequent time ;-)

    @mysql_query($q );

    // Insert any new image into database

    if ($_REQUEST[completed] == 1) {
    // Need to add - check for large upload. Otherwise the code
    // will just duplicate old file ;-)
    // ALSO - note that latest.img must be public write and in a
    // live appliaction should be in another (safe!) directory.
    move_uploaded_f ile($_FILES['imagefile']['tmp_name'],"latest.img ");
    $instr = fopen("latest.i mg","rb");
    $image = addslashes(frea d($instr,filesi ze("latest.img" )));
    if (strlen($instr) < 149000) {
    mysql_query ("insert into pix (whatsit, imgdata, firstname, lastname, address) values (\"".
    $_REQUEST[whatsit].
    "\", \"".
    $image.
    "\", \"".
    $_REQUEST[firstname].
    "\", \"".
    $_REQUEST[lastname].
    "\", \"".
    $_REQUEST[address].
    "\")");
    mysql_query($qu ery) or die('Account Created redirecting please wait... <meta http-equiv="refresh" content="3;URL= #">');
    } else {
    $errmsg = "Too large!";
    }
    }
    [/PHP]

    Thanks In advance!
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Firstly, you already got an answer on how to validate. You even did a tutorial, so what else could you want to know about this topic. You can do the programming yourelf (I hope). And if you cannot, follow a PHP tutorial.

    Secondly, why on earth do you want to perform file type checking on a hardcode file name (.img)?

    Ronald

    Comment

    • underground
      New Member
      • Sep 2006
      • 41

      #3
      Originally posted by ronverdonk
      Firstly, you already got an answer on how to validate. You even did a tutorial, so what else could you want to know about this topic. You can do the programming yourelf (I hope). And if you cannot, follow a PHP tutorial.

      Secondly, why on earth do you want to perform file type checking on a hardcode file name (.img)?

      Ronald
      I want to make sure a specific file type is being upload rather a txt file or exe into a database. The Structure of this query is kinda weird to me, it not the file hardcode I'm concerned about but rather what's actually in the database!

      But hey it's all good, nice to here from ya!

      Comment

      Working...