将上传的文件转换为无法下载的特定文件格式
我有一个关于阻止下载和保存上传文件的问题。
我的用户可以上传多种文件类型,如 doc、pdf、ppt 等...
如果任何文件类型有 url,则所有文件类型都可以轻松下载。
那么有什么更好的方法来阻止文件的下载呢?
或者我将上传的文件转换为某种无法轻松下载的特定格式(例如flash)..
我在php和mysql上运行。
谢谢
阿维纳什
I have a problem regarding to prevent download and saving of uploaded files.
My users can upload multiple files types like doc, pdf, ppt,etc....
This all file types are easily download if any one have url.
So what is the better way to prevent the download of the file.
Or i convert the uploaded files to some specific format which can not download easily (e.g flash)..
I am running on php and mysql.
Thanks
Avinash
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这方面你有两种选择。第一种方法是通过 PHP 脚本将文件移动到服务器 Web 目录之外的服务器端文件夹。第二种是将文件存储在 BLOB 列中一个 MySQL 表。两者都会阻止用户直接访问文件,而无需将文件转换为不易下载的格式。
You have two options in this regard. The first is to move the files, through a PHP script, to a server-side folder outside of the server's web directory. The second is to store the files in a BLOB column in a MySQL table. Both will prevent users from accessing the files directly, without the need to convert the file to a not-so-easily-downloaded format.
将文件上传到文档根目录之外。例如:
您的文档根目录在哪里,
因此无法直接访问它们。然后,如果您想允许下载,请创建一个名为“download.php”的 PHP 文件,该文件执行类似以下操作:
显然您可以添加检查以查看用户是否具有下载此特定文件的适当权限或是否已登录。
Upload the files outside of your document root. For example:
where your document root is
So they can't be accessed directly. And then if you want to allow downloads, create a PHP file called "download.php" that does something similar to:
and obviously you can add checks to see if the user has the proper permissions to download this particular file or is logged in.
解决方案可以是为上传文件夹设置用户和密码,这样只有知道身份验证详细信息的用户才能下载文件。
检查下一个链接,了解如何在服务器文件夹上创建 htpasswd 文件:
http:// /httpd.apache.org/docs/1.3/programs/htpasswd.html
A solution can be to set a user and a password to the upload folder, so only the users that know authentification details can download files.
Check next link for learn how to make htpasswd files on your server folders:
http://httpd.apache.org/docs/1.3/programs/htpasswd.html