虽然这个答案可能并不代表“最佳实践”,它的工作很好
我们使用后端服务器Apache作为各种各样的“文件服务器” - 服务于私人文件和图像用户上传到他们的帐户。这是它是如何工作的:
设置mod_rewrite来处理你想要的URL。例如:
RewriteRule /content/(.*) /ServeContent.php?FileName=$1
脚本ServeContent.php将做到以下几点:
1. Validate input
2. Authenticate user based on cookie or session data
3. Make a URL with $_GET['FileName'] and the IP of the backend server
http://192.168.1.30/content/somefile.jpg
4. Set appropriate headers for the file type
header('Content-type: image/jpeg')
5. readfile($URL)
这种方法要求的fopen,包装在支持PHP。 readfile
不会将内容存储在内存中,所以这确实不会占用太多内存。其中一个主要的缺点是,在请求期间(可能会很长时间),您将持有apache/php进程。但实际上,除非您运营的是高流量的网站,否则您很可能不会遇到问题。
如果你是,那里最有可能更好的解决方案。但是这对我们在各种应用程序中的大文件非常有效。
叹气,我希望能工作。我的内容服务器上的某些“内容”是HTML页面的文件夹,其中包含与其他页面和图像的相关链接。 – KevMo 2009-11-02 16:53:41
你确定有问题吗?发送文件时,您不能检测或确定正确的内容类型吗? – gahooa 2009-11-03 02:16:02
再次看到您的答案,它看起来像会工作。这种方法对使用.htaccess和cookie有什么优势? http://www.willmaster.com/blog/contentprotection/htaccess-cookie.php – KevMo 2009-11-03 05:14:30