Hello people,
as I am new to this forum my apology to the admin(s) and to all if I broke some of the rules here.
My actual problem is as the title itself says, below you will find a part of the code where foreach() loop is made through the strings written in a file called keys, where after the link is generated, it does not delete itself automatically after expiry, but only if clicked. I have tried with $one = “” and $one = ‘’, but it doesn’t work either.
Please help,
Xedeus
$fid = base64_decode(trim($_GET['fid']));
$key = trim($_GET['key']);
// Calculate link expiration time
$currentTime = time();
$keyTime = explode('-',$key);
$expTime = strtotime(EXPIRATION_TIME, $keyTime[0]);
// Retrieve the keys from the tokens file
$keys = file(TOKEN_DIR.'/keys');
$match = false;
// Loop through the keys to find a match
// When the match is found, remove it
foreach($keys as &$one){
if(rtrim($one)==$key){
$match = true;
$one = "";
}
}
// Put the remaining keys back into the tokens file
file_put_contents(TOKEN_DIR.'/keys',$keys);
// If match found and the link is not expired
if($match !== false && $currentTime <= $expTime){
// If the file is found in the file's array
if(!empty($files[$fid])){
// Get the file data
$contentType = $files[$fid]['content_type'];
$fileName = $files[$fid]['suggested_name'];
$filePath = $files[$fid]['file_path'];
// Force the browser to download the file
if($files[$fid]['type'] == 'remote_file'){
$file = fopen($filePath, 'r');
header("Content-Type:text/plain");
header("Content-Disposition: attachment; filename=\"{$fileName}\"");
fpassthru($file);
}else{
header("Content-Description: File Transfer");
header("Content-type: {$contentType}");
header("Content-Disposition: attachment; filename=\"{$fileName}\"");
header("Content-Length: " . filesize($filePath));
header('Pragma: public');
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (10)));
readfile($filePath);
}
exit;
}else{
$response = 'Download link is not valid.';
}
}else{
// If the file has been downloaded already or time expired
$response = 'Download link is expired.';
}