The solution that comes to my mind is as follows: If you have a table that represents a file and, for example, FileModel, you can save there the file name, some details, size, and also the file path in your file system and unique , which may be the result of md5 from some of the data that you choose for it is based on some files, for example:
$data[FileModel]['unique'] = md5(time() . $data[FileModel]['file']);
Each time before allowing someone to upload a file, you check to see if your table has such a unique value, if you allowed someone to upload it using the ur downloadFile method created in FileModel, but before that you create a new unique one way to prevent downloads
$data[FileModel]['unique'] = md5(time() . $data[$this -> name]['file']); $this -> FileModel-> save($data[$this -> name]); $this -> FileModel -> downloadFile($data[$this -> name]);
If the ur database does not have such a unique value, you simply display an error about the timeout for the user link
$this -> setFlashError('link expired');
Here I pase for you an example prototype action with which you can start from your controller:
function download($file_data = ''){ $data = $this->FileModel->find('first', array('conditions' => array('FileModel.unique' => $file), 'fields' => array('*'))); if(!is_array($data[FileModel])) $this -> setFlashError('link expired'); else { $data[FileModel]['unique'] = md5(time() . $data[$this -> name]['file']); $this -> FileModel-> save($data[$this -> name]); if(!$this -> FileModel -> downloadFile($data[$this -> name])) { $this -> setFlashError('error')); } } }
You can also create a datetime field, where you can add, for example, 1 day to the current date and check the time remaining before loading has expired.
scx
source share