允许受保护目录中的 PHP 脚本
我有一个名为“templates”的文件夹,其 CHMOD 777 并受 htpasswd 保护。这意味着我仍然可以使用 PHP 上传脚本将文件上传到该文件夹,并且外部人员无法访问这些文件。
我还得到了一个使用 phpmailer 类的脚本。该脚本发送电子邮件并附加位于该受保护文件夹中的文件。
我的问题是,现在我启用了此保护,我确实收到了电子邮件,但没有附件。我只有在没有 htpasswd 保护的情况下才会收到附件。
知道我能做什么吗?
I've got a folder named 'templates' which is CHMOD 777 and protected by a htpasswd. This means I can still use my PHP upload script to upload files into that folder and people from outside cannot access these files.
I also got a script which uses the phpmailer class. This script sends e-mails and attaches a file which is located in that protected folder.
My problem is that now that I got this protection enabled, I do receive the email but without attachment. I only receive the attachment once there is no htpasswd protection.
Any idea's what I could do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PHP 在网络服务器的 htpasswd 保护范围之外运行 - 一旦脚本运行,它就可以自由控制文件系统(至少是网络服务器的 userid/groupid 可以触及的内容)。除非您以 URL 的形式提供要附加的文件的路径,否则对该文件的任何操作都将通过正常的文件系统操作,而不是通过网络服务器,因此 htpasswd 保护不会进入其中。
如果未附加文件,我会检查脚本并查看您是否提供了文件的适当路径,以及网络服务器的用户 ID 是否具有该文件的读取权限。
PHP operates outside of the bounds of the webserver's htpasswd protection - once the script's running, it has free reign over the file system (at least, the stuff that the webserver's userid/groupid can touch). Unless you're providing the path to the file-to-be-attached as a URL, any operations on that file will go through the normal filesystem operations, and not via the webserver, so htpasswd protection does not enter into the picture.
If the file's not being attached, I'd check the script and see if you're providing the appropriate path to the file, and if the webserver's userid has read permissions on the file.
确保您的脚本将附件文件作为文件系统上的路径访问,例如
不是作为 URL
确认脚本可以访问该文件
Make sure your script is accessing attachment files as paths on the file system, like
Not as URLs
Confirm that the script can access the file