在 PHP 中移动文件(与上传文件有关)

发布于 2024-11-24 03:26:30 字数 129 浏览 3 评论 0原文

我有一个网站,人们可以大量上传大型(2mb-3mb)文件。所以我需要将它们存储在外部驱动器(我的 drobo)上。如何将文件上传到服务器上的文件夹,然后如何编写一个 php 脚本来检索它们并让用户下载它们。

谢谢, 乔伊·萨基尼

I have a site that people upload large (2mb-3mb) files to, In large quantities. So I need to store them on an external drive (my drobo). How can I upload files to a folder on the server and then how can I write a php script that retrieves them and lets users download them.

Thanks,
Joey Sacchini

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

萌辣 2024-12-01 03:26:31

为此,只需将文件移至可访问的空间即可。

http://php.net/manual/en/function.move-uploaded -file.php

不过,请务必考虑这一点的含义。将上传的文件移动到开放目录后,任何人都可以访问它。这是非常危险的。想象一下有人上传 PHP 脚本。

最好创建一个从 Web 根目录之外的位置获取文件的脚本。在基本级别上,您可以将文件的属性(例如原始名称(您应该将它们重命名为磁盘上的随机名称)和 mimetype)存储到数据库中。然后使用 readfile()

要将备份下载到您自己的个人硬盘,只需使用 SFTP。

To do this, simply move your files into an accessible space.

http://php.net/manual/en/function.move-uploaded-file.php

Be sure to consider the implications of this though. Once you move an uploaded file to an open directory, anyone can access it. This is very dangerous. Imagine someone uploading a PHP script.

It is best to create a script that fetches files from a location not in the web root. At a basic level, you can store the file's properties, such as original name (you should rename them to something random on disk) and mimetype, to database. Then send the file to the client with readfile().

For downloading backups to your own personal hard drive, just use SFTP.

零度℉ 2024-12-01 03:26:31

这不是一个快速答案,您需要了解如何上传、检索文件并将其保存到服务器;设置 PHP 的写入权限和其他一些内容。我建议您尝试这些链接来快速入门:

http://www.w3schools.com/php /php_file_upload.asp

http://www.tizag.com/phpT/fileupload.php

另请访问 PHP 参考手册以获取一些很棒的示例。

This is not a quick answer, you need to understand how to upload, retrieve, and save the file to the server; set write permissions for PHP and a few other things. I suggest you try these links to get you started fast:

http://www.w3schools.com/php/php_file_upload.asp

http://www.tizag.com/phpT/fileupload.php

Also visit the PHP reference manual for some great examples.

愛上了 2024-12-01 03:26:31

那么您可以将上传的文件保留在服务器目录之外。因此,如果您的服务器根目录是 /www/htdocs,您可以将文件保存在 /uploaded 中。所以使用这样的

move_uploaded_file($_FILES['file'],'/uploaded')

方式你的文件将无法被外界访问

well u can keep the uploaded files outside of server directory. so if ur server root is /www/htdocs u can keep the files in say /uploaded. so use something like

move_uploaded_file($_FILES['file'],'/uploaded')

this way ur files will be inaccesible to the outside world

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