BIF3
[ class tree: BIF3 ] [ index: BIF3 ] [ all elements ]
Prev Next
File Uploading

We need to upload some files to our aplication. It's very simple to add IDM fields that include a file uploading directlly to our database.

For example an IDM that has a Description and a file sould have in it's fileds:
$this->fields = array(
     array(id,"int(11) NOT NULL  auto_increment PRIMARY KEY",
           FTShow,,
           ,,true),
     array(Attach,"MediumBlob",
           FTFile,,
	   ,base64_encode,false), //try true if it doesn't work... 
     array(Attach_filename,"varchar ( 255 )",
           FormHidden,AT="OUTSIDE",
           ,,true),
     array(Attach_filesize,"varchar ( 255 )",
           FormHidden,AT="OUTSIDE",
           ,,true),
     array(Attach_filetype,"varchar ( 255 )",
           FormHidden,AT="OUTSIDE",
           ,,true),
     array(Description,"mediumtext NOT NULL",
           FTTextarea,rows="5" cols="50",
           ,,true));

now we could use that class (just like any other IDM class) to insert, modify

As version 0.3.12, we still have problems modifing files.

and delete.

If the user wants to download the file, we should make a download.php script in our aplication similar to this:
<?php

include_once(bifConfig.inc.php);

if( ! (     $table= $_SESSION[_BifApplication]->getParameter(table) 
	AND $id=    $_SESSION[_BifApplication]->getParameter(id)
	AND $field= $_SESSION[_BifApplication]->getParameter(field)
	AND $field_id= $_SESSION[_BifApplication]->getParameter(field_id)

 ) ){
  // TODO: write a nice little page saying invalid download
  die(Invalid download!);
}
    // TODO: CHECK $table and $id $field .. etc.
    // TODO: check if is in session... (so no other users can download arbitrary info)


$query = " SELECT $field,${field}_filename,${field}_filesize,${field}_filetype
FROM $table
WHERE
$field_id = $id
";

// TODO: some other checks like if table.field is BLOB or similar

$rst = $_SESSION[_BifApplication]->execQuery($query);

// TODO: check if there is some prblems with the query, and report the error!

$row = $rst->fetchRow(DB_FETCHMODE_ASSOC);

header(Content-Type: .$row["${field}_filetype"]);
header("Content-Length: ".$row["${field}_filesize"]);
header("Content-Disposition: attachment; filename=\"".$row["${field}_filename"]."\""); 
print base64_decode($row[$field]);

?>

Now http://site/download.php?table=table&id=1&field_id=id&field=Attach will start downloading the file

As you can see there is a lot of checking missing, but this is a start. You are welcome to join the development team so BIF

Prev   Next
Building a BIF Application Debugging

Documentation generated on Wed, 10 Nov 2004 19:41:19 -0300 by phpDocumentor 1.2.3