将上传的文件转换为无法下载的特定文件格式

发布于 2024-08-23 22:38:18 字数 226 浏览 2 评论 0原文

我有一个关于阻止下载和保存上传文件的问题。

我的用户可以上传多种文件类型,如 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌生 2024-08-30 22:38:18

在这方面你有两种选择。第一种方法是通过 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.

混浊又暗下来 2024-08-30 22:38:18

将文件上传到文档根目录之外。例如:

/var/username/uploads/file.docx

您的文档根目录在哪里,

/var/username/public_html/index.php

因此无法直接访问它们。然后,如果您想允许下载,请创建一个名为“download.php”的 PHP 文件,该文件执行类似以下操作:

$data  = file_get_contents('/var/username/uploads/file.docx');
header('Content-Type: application/docx');
header('Content-Length: '.strlen($data));
header('X-Content-Type-Options: nosniff');
echo $data;

显然您可以添加检查以查看用户是否具有下载此特定文件的适当权限或是否已登录。

Upload the files outside of your document root. For example:

/var/username/uploads/file.docx

where your document root is

/var/username/public_html/index.php

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:

$data  = file_get_contents('/var/username/uploads/file.docx');
header('Content-Type: application/docx');
header('Content-Length: '.strlen($data));
header('X-Content-Type-Options: nosniff');
echo $data;

and obviously you can add checks to see if the user has the proper permissions to download this particular file or is logged in.

我家小可爱 2024-08-30 22:38:18

解决方案可以是为上传文件夹设置用户和密码,这样只有知道身份验证详细信息的用户才能下载文件。
检查下一个链接,了解如何在服务器文件夹上创建 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


~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文