Page 1 of 1

Download, then unlock

Posted: Mon Nov 22, 2010 9:41 am
by pomdah
I am building a PHP site for a small business where the customer should be able to download a file and then get a key in the mail to unlock it when he/she has paid. Anybody who knows where to find methods for this?

Re: Download, then unlock

Posted: Mon Nov 22, 2010 1:21 pm
by DaveTheAve
Have the original uncompressed file uploaded to a non-public folder on the site, then when the user pays for it, have PHP run the command line to compress the orginal file to a /tmp file with the key you will email the buyer and present that compressed file to the buyer to download.

Re: Download, then unlock

Posted: Mon Nov 22, 2010 2:00 pm
by pomdah
Thanks, sounds simple enough. Could you give some advice about compression/encryption methods, too?

Re: Download, then unlock

Posted: Mon Nov 22, 2010 2:23 pm
by DaveTheAve

Code: Select all

system('zip -P pass file.zip file.pdf');
Simple enough and should give you a nice idea.

Also, This should help you as well.

Re: Download, then unlock

Posted: Mon Nov 22, 2010 3:01 pm
by pomdah
Thanks again, embarrassed I didn't find that myself.

Re: Download, then unlock

Posted: Mon Nov 22, 2010 3:05 pm
by DaveTheAve
Don't worry about it. I ask lots of questions here and half the time I feel stupid too. It's just a part of learning!

Re: Download, then unlock

Posted: Tue Nov 23, 2010 9:01 am
by Bind
Another option would be to encrypt the pdf file itself on the fly with php. You can also use php to automatically generate the pdf file as well, and use php do allow them to download it upon payment (with automatic confirmation like through paypal verifying it with their IPN API).

You could also design an entire system for it. User accounts allowing them automatic and immediate access to the resource they have paid for, right away when they make their payments. PHP can then stream them the pdf from a protected directory.

... which would eliminate the need to "protect" and "unlock" your pdf's.

Automation is a good thing. Saves valuable time and money.

PHP's PDF Manual
Protect PDF Files with PHP
PayPal Instant Payment Notification (IPN) Introduction
PayPal Instant Payment Notification (IPN) Code Samples