Store blobs are downloadable attachments Default: Attachments are files which are stored in the database. These are stored using blob, image or bytea (for postgresql) types. When you store the attachment, phplens will also store the file name and file size in readable format in a separate varchar field. If the blob field is called myblob and the varchar field is called myfiledetails, then set
$lens->attachment = 'myblob;myfiledetails';
The second field (myfiledetails) is optional.
You need to configure your phplens SQL statement in a special manner when using attachments. If the table is called myfiles, and has a primary key id then the following SQL is required:
$lens->sql = 'select id, myfiledetails, 0 as "_ATTACHMENT_" from myfiles';
You do not directly access the attachment fields in your SQL because you don't want to retrieve the attachment data (it could be a several very large attachments) everytime you view the phpLens grid. _ATTACHMENT_ is a special alias to the actual field, with a dummy value (0 in this case, though it could be any constant value). PhpLens will detect the _ATTACHMENT_ field and will display a download link when viewing the grid or details. When editing or creating records, the standard upload field form will be shown.
The file info field, myfiledetails in the above example, is also special. You can make it visible in the grid or details. But make sure it is readonly or hidden in the edit/new record form. This field will be automatically filled with the file name and size on record update.
The maximum size of an upload is determined by the imageMaxSize property. There can only be 1 attachment field per record.
Blob Header Format
All BLOBs begin with a header. The first bytes of the header are defined by a constant LENS_ATTACH_HDR in phplens.inc.php. The final bytes of the header consists of '/'.LENS_ATTACH_HDR. Between the header and the end of the header is the header contents.
In phpLens 3.5.0, the header contents is the name of the attachment. In phpLens 3.5.1 and later, it is a MIME content-type definition that looks like this:
/Content-Type: application/octet-stream; name="some file name"
No double-quotes are allowed in the file-name. All double-quotes will be changed to dot (.).
Sample Header:
1@#Cm&NT/Content-Type: application/octet-stream; name="file.jpg"/1@#Cm&NTSyntax
$lens->imageMaxSize = 1024*1024; // 1 Mb upload
$lens->attachment = 'myblob;myfiledetails'; Basic:Yes Advanced/Enterprise:Yes DynamicEdit:Yes [Version 3.5]
|