限制,所以只有相关的上传者可以下载他们的文件



我正在建立一个小网站,允许用户从服务器上传和下载他们的个人文件。Codeigniter被用于这个项目,我正在使用文件上传类来上传文件。

出现的问题是我如何确保只有上传文件的人才能下载它。目前所有的文件都上传到localhost/curious/uploads。虽然文件只对上传者可见,但如果他们共享上传链接,任何人都可以下载文件。

如果Steve上传了一个名为secure_rom.doc的文件路径是localhost/curious/uploads/secure_rom.doc这个文件可以被任何有链接的人下载

如何确保只有上传者可以从下载区下载,而不是其他人?

您可以使用下载脚本(尝试使用codeigniter)

1)检查用户是否已登录

2)设置标题为文件名和内容类型

3)读取文件并发送给客户端!

控制器:

if($userConnected) {
 header('Content-disposition: attachment; filename=' . $file_name);
 header('Content-type: ' . $file_mime);
 $file_content = file_get_contents($file_location);
 echo $file_content;
}
else 
 echo 'No permission !';

Mime内容函数

Easy Way

-just store the 'id' of the user when he/she uploaded something.
- hide the URL if 'user_id' is different.
- adding random character will have in securing.

相关内容

最新更新