Check permission and log download with PHP, but use original link to download the file?
Get the solution ↓↓↓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;
?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: constant expression contains invalid operations
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.