HOW TO allow saving and downloading of BLOB files?

Talk and info about common issues

Moderator: alexandrleonenko

administrator
Site Admin
Site Admin
Posts: 6098
Joined: Jan 7th, '09, 23:18
Contact:

HOW TO allow saving and downloading of BLOB files?

Postby administrator » Nov 28th, '11, 10:51

FOR NEW VERSIONS - v7.4.9 or above

DataGrid from v7.4.9 provides full support for storing/downloading BLOB files (if you add "save_as"=>"blob").

Below the simple instruction of how to allow downloading such files.

1. Create 3 fields for BLOB file in your database to store filetype, filename and filesize:
"blob_type", "blob_name", "blob_size"

2. Define these fields in your "file/image" field in a following way:

Code: Select all

"save_as"=>"blob", "blob_filetype"=>"blob_type", "blob_filename"=>"blob_name", "blob_filesize"=>"blob_size"

3. That's all! You may now test it.


FOR OLD VERSIONS

DataGrid from v7.0.0 allow to store BLOB files (if you add "save_as"=>"blob").

Example:

Code: Select all

"blob_content" => array(
"header"=>"File",
"type"=>"file", 
......
"save_as"=>"blob"),


Below the simple instruction of how to allow downloading such files.

1. Read carefully this example: http://onlamp.com/php/2000/09/15/examples/example5.html

2. Create 3 fields for BLOB file in your database to store filetype, filename and filesize.
Add changes in datagrid.class.php to save appropriate values in these fields after the file was uploaded.

3. Add to DataGrid after

Code: Select all

$output .= "[BLOB] - ".$sizeinbytes." Kb";


following:

Code: Select all

if($fp_allow_downloading) $output .= "<a class='x-blue_dg_a' href='".$fp_target_path.$field_value."' title='".$this->lang['click_to_download']."'>[".$this->lang['download']."]</a>";                           


TIP1:
Remember that BLOB as defined in MySQL only has a 64K limit... regardless, of course what PHP allows for uploading docs. Change your MySQL def to MEDIUMBLOB and your max is now 16M... normally plenty... and this is what may resolve all opening/uploading issues for you.

TIP2:
If you do not like going from the Edit screen (where you add the file) and then exiting and back into the Details view or download documents after uploading, you may came up with another solution. In our SQL statement at the top of the datagrid code create a virtual field and use it as a link to separate page, where you may write all needed procedures. Just remember to pass there a document ID.

Return to “ApPHP DataGrid {HOW TO}”