PHP Cool Paypal Script - Digital Downloads Made Easy

Last updated on
Subscribe to Internet Tips and Tools Feed

Are you looking for a way to easily allow digital downloads of files after a paypal payment is received? This PHP script uses the latest Paypal Express Checkout method.


This script does the following with one php file, without any other scripts needed:

		1. Request token from paypal
		2. Create a payment by sending payment json object to paypal
		3. Redirect user to Paypal with returned 'approval_url'.
			Paypal will redirect back to this file after payment.
		4. Execute payment with paypal
		5. Create encrypted download link that expires
		6. When user clicks link, send download file to customer


Paypal requires TLS v. 1.2 which requires OpenSSL 1.0.1c. For more information see:


  1. Create a "Buy Now" link to coolpaypal.php on your html page similar to: coolpaypal.php?

    You can use this code which includes a Paypal Buy Now button:

  2. Go to:
  3. Click Log into Dashboard.
  4. In the REST API apps section, click Create App.
  5. PayPal generates a set of OAuth client_id and secret credentials for your app for both the sandbox and live environments. To test it you need to use sandbox accounts. On the left side of the Paypal Dashboard under Sandbox click Accounts. The test account to test a purchase with will look something like ""
  6. After testing click on your app under App Name at and click on live and copy your live client_id and secret and change $mode to "live".


Buy Now    You may download and use the script after a paypal payment of $25.00. This "Buy Now" button uses the script you are about to download.

Or download the script to setup and test for a donation: dlc_b


Downloaded 0 times.
Please make a donation to reveal the download link.


10/21/2019 - Version 1.2 - This month Paypal started rejecting the payment request with http code 415 (Unsupported Media Type) because something changed on Paypal's servers in detecting Content-Tpye of "application/json" header. Found out it was because the header was previously with a space between Content-Type and the colon. Changed it to 'Content-Type: application/json' throughout the code and now it works again.

12/18/2018 - Version 1.1 - Added support for a download countdown to auto start download and changed the download method from using readfile() to using fopen() with file chunks for better support at downloading larger files on servers with limits.

8/25/2017 - Version 1.0 - Paypal Digital Download Script Created

Last updated on October 21, 2019
Created on August 25, 2017

Back to
Subscribe to Internet Tips and Tools Feed        

User Comments

There are 11 comments.

Displaying first 50 comments.

1. Posted By: OneGuy - - April 16, 2019, 12:52 pm
How does this work for subscriptions and recurring invoices?

2. Posted By: Jeff - - April 16, 2019, 7:26 pm
Hi OneGuy,

It does not work for subscriptions. This script is for purchasing and then downloading an individual file such as a music file, a photo, a document, etc.


3. Posted By: Joe - - April 22, 2019, 8:41 am
Hi - it seems to be a great script - one question before buying it: Can I modify the list with the download files individually (I must indicate some features like format-size-author-production and so on) AND - can I offer free downloads within the list too? Is the size of the download-files limited?
thanks so much for answering

4. Posted By: Jeff - - April 22, 2019, 10:32 am
Hi Joe,

You can edit the PHP file and specify the filenames and prices. It is setup to edit with simple if statements like this:

// Setup your file names and prices here:
if ($file=="")
else if ($file=="")

As for indicating format-size-author-production and so on you would specify that in your html file. Also any free files would go through html and not through the paypal script. The size of the download files is not limited by the script but you may have some settings on your php server that limit the file size.


5. Posted By: Jeff - - April 23, 2019, 10:26 am
Hi Joe,

1. License: You may use the script on any page on your own website. Additional website domains should purchase their own copy of the script.
2. SQL is not used.
3. The script does not bill or email the user. It sends the user to paypal where they complete a payment with paypal and then they are sent back to the website where the download of the file begins.
4. The link will last until the amount of hours you specify in the script. You can set it to last for 1 to 24 hours. The link does not need to be secure. The only way to make it secure is if you require that your website be run over https.


6. Posted By: Chad - - October 17, 2019, 8:42 pm
I am getting a error I think its 416? or something like that but i haven't change anything so i don't know why this is happening. Do you know what this error means? thanks

7. Posted By: Jeff - - October 18, 2019, 8:55 am
Hi Chad,

The error is on Paypal's end. They changed something. I have a support ticket submitted with them. Hopefully they will get back to me soon. If you would like to submit a support ticket to Paypal then maybe they will get more techs on the problem. I submitted it here:  


8. Posted By: vinbon - - November 30, 2019, 4:57 am
hey it looks like a very dead link

9. Posted By: Jeff - - November 30, 2019, 12:22 pm
Hi vinbon,

Thank you for notifying me. Sorry about that. There was a mysql error on the server. It is fixed now


10. Posted By: vinbon - - November 30, 2019, 3:34 pm
Hi Jeff,
the new link works fine, thanks a lot, bye

11. Posted By: RS - - August 6, 2021, 7:48 am
Would it be possible to specify the quantity of the item too? I know there can be no control over how many times it's downloaded, so there's an element of trust, but I would like the buyer to be able to select - say - 30 to allow them to copy the book to 30 devices. If the book is $5, that would then mean the total charge would be $150, of course.