Check permission and log download with PHP, but use original link to download the file?

48
March 16, 2019, at 03:50 AM

I'm using the following code to check if a user has permission to download a file and to log that s/he downloaded it. It works good, but the files are hosted on Dropbox and I assume that the files are downloading through my server? I have recently gotten CPU spikes and complete server stalls so I'm looking into the option of either optimizing my code below if possible, or make so the access check and download count happens and then you're redirected to the dropbox link. Any suggestions?

<?php
/* PHP code here (not included in this snippet) to check for access and log download */
session_write_close();
header("Cache-control: private");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"file.mov\"");
       header('Content-Transfer-Encoding: binary');
// Disable caching
header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
header('Pragma: no-cache'); // HTTP 1.0.
header('Expires: 0'); // Proxies.
readfile('https://dropboxlink...');
exit;
?>
READ ALSO
How to fix file not found on Heroku?

How to fix file not found on Heroku?

I have a laravel project deployed in Heroku, in my Laravel project i have a php script i made to receive json, my php script is in public folder, when i use php artisan serve to serve the project, the script is accessible with no problem through the following...

39
How to set a shipping cost by item in Woocommerce

How to set a shipping cost by item in Woocommerce

In Woocommerce, when I add multiple products in cart, the shipping only applies to to 1 productHow should I change that to apply the cost to each item?

20
Show table with conditions from 2 input fields

Show table with conditions from 2 input fields

I'm having problems showing filtered table under 2 conditions from my database table

23
Why I can&#39;t change html format to php format

Why I can't change html format to php format

I got admin panel template from Creative TIM and I want to programing it from scratch but I can't write PHP commands inside HTML so I tried change it from dashboardcomponent

29