Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Download link for PDF stored as blob

Locked
mlgeek
Posts: 23
Joined: Tue May 08, 2012 8:24 pm

Download link for PDF stored as blob

Unread post by mlgeek »

Howdy!

My application needs to store just a couple of files, so I'd rather not go the route of integrating BOX- I'd prefer just to allow the user to upload a file, store it as a blob in MySQL, then allow the user to download it later.

I've got the upload set up just fine.

I understand this content and can use it to display the NAME of the uploaded file...
http://wiki.nubuilder.com/tiki-index.ph ... uilderDocs

...but I'm still wrestling with how to generate a link to allow the user to download the file. Any guidance available?
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Download link for PDF stored as blob

Unread post by massiws »

mlgeek ,

- 1) add a text object on your form that shows the file name (when the record is saved):
form.png
- 2) to open the file object called xyz you can insert this code in On Double Click field of the text object:

Code: Select all

var docName = $('#xyz_file_name').val();
if (docName != '') {
	runIt('showDoc', docName);
}
img.png
- 3) in Setup > Add Activity add a showDoc procedure that select and show the file:

Code: Select all

/* Get record from db using parameter passed through runIt() via a hash id */

$par = '#runIt1#';
$sql = "SELECT * FROM your_table WHERE xyz_file_name = '" .$par. "'";
$fileObj = db_fetch_object(nuRunQuery($sql));

$file     = $fileObj->xyz;
$fileName = $fileObj->xyz_file_name;
$fileType = $fileObj->xyz_file_type;

header("Content-type: ".$fileType);
header("Content-Disposition: attachment; filename=".$fileName);
header("Pragma: private");
header("Cache-control: private, must-revalidate");
 
/* show the file */
echo $file;
Hope this helps.
Max
You do not have the required permissions to view the files attached to this post.
mlgeek
Posts: 23
Joined: Tue May 08, 2012 8:24 pm

Re: Download link for PDF stored as blob

Unread post by mlgeek »

Belated but huge thanks, Max!
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Download link for PDF stored as blob

Unread post by admin »

.
Locked