Я хочу, чтобы пользователи могли загружать .pdf и изображения и ограничивать доступ к этим файлам на основе прав пользователя. Кто-нибудь сделал что-то подобное? Основной план присоединения, который я думал о контроллере, проверяет, имеет ли пользователь права на просмотр документа или файла. Если у них есть привилегии, документ извлекается и отображается.Ограничение на Assests .pdf .jpg
Мой .htacces файл будет включать в себя
#Removes access to the secure_files folder by users.
RewriteCond %{REQUEST_URI} ^secure_files.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
------
-SQL
------
------
- create files table
-----
CREATE TABLE `files` (
id INT NOT NULL AUTO_INCREMENT,
file_name VARCHAR(50) NOT NULL,
PRIMARY KEY('id')
);
------
- create files table
-----
CREATE TABLE `privileges` (
uesr_id INT NOT NULL,
file_id INT NOT NULL,
);
------
- create users table
-----
CREATE TABLE `users` (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(20) NOT NULL,
email VARCHAR(50) NOT NULL,
password CHAR(40) NOT NULL,
PRIMARY KEY('id')
);
/*
* pseudo-Codeigniter code. I can edit this to make
* it pure PHP if that would be more helpful
*
*/
public function get_user_files($filename)
{
//this is set during login
$user_id = $this->session->userdata('user_id');
//check to see if the user has privileges to access the file and gets the file name
$query = $this->db->join('privileges','privileges.id = files.id')
->select('files.file_name')
->where('privileges.user_id',$user_id)
->where('files.file_name',$file_name)
->limit(1)
->get('files');
$file = $query->row()->files.file_name;
if($file)
{
//user has privileges to access the file so include it
//WHAT DO I DO HERE!?!
//start Would this work?
$handle = fopen($file, "rb");
$data['file'] = fread($handle, filesize($file));
fclose($handle);
//end would this work?
}
$this->load->view('files',$data);
}
О, простые решения всегда самые лучшие! Я всегда соглашался с людьми, которые говорят, что не хранят изображения и документы в БД, но в этом случае главная проблема в управлении доступом - это лучшее решение. Спасибо, что вы это поняли. – John