사용자가 .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);
}
아, 간단한 해결책은 항상 최고입니다! 나는 이미지와 문서를 DB에 저장하지 말라는 사람들과 항상 동의했지만,이 경우 액세스 제어의 주요 관심사이므로 최상의 솔루션입니다. 이 문제를 해결해 주셔서 감사합니다. – John