以编程方式“交付”文件 [英] Programmatically "deliver" file

查看:52
本文介绍了以编程方式“交付”文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的下载部分不可浏览(对用户),但

可以访问脚本。


我可以将文件传送到浏览器而不用链接到它的URL,以便我

可以以编程方式提供文件但阻止用户浏览或链接到他们的



我在apache服务器上使用PHP。


Ta

I would like to make my downloads section unbrowsable (to users) but
accessible to scripts.

Can I deliver a file to a browser without linking to it''s URL so that I
can deliver files programmatically but prevent users from browsing or
linking to them?

I am using PHP on an apache server.

Ta

推荐答案

< a href =mailto:St *********** @ gmail.com> St *********** @ gmail.com 写道:

我想让我的下载部分不可浏览(给用户)
但可以访问脚本。

I would like to make my downloads section unbrowsable (to users)
but accessible to scripts.




有两种方式实现这个:


1.将下载目录放在文档根目录之外。


并非所有主机都允许这样做,但通常会执行此操作有这样的初始设置




\ [根目录]

\public_html


当客户请求时,例如, www.yoursite.com /index.php

index.php从public_html目录提供。

根目录仍然无法通过HTTP访问。所以

你可以做的是放置你的下载目录

在\public_html之外:


\ [根目录]

\ public_html

\downloads


然后你的下载脚本可以这样做:


header(''Content-Type:application / zip'');

readfile(''/ downloads / somefile.zip'');


2.使用.htaccess文件保护下载目录。


您的下载目录可以位于

文档根目录内,但是您可以通过将.htaccess文件放在包含

以下指令的目录中来禁用对它的HTTP访问




订购允许,拒绝

拒绝所有


然后您的下载脚本可以执行以下操作:


header( ''Content-Type:application / zip'');

readfile(''downloads / somefile.zip'');


干杯,

NC



There are two ways to implement this:

1. Place the downloads directory outside the document root.

Not all hosts allow this, but those that do typically have
an initial setup like this:

\ [Root directory]
\public_html

When a client requests, say, www.yoursite.com/index.php,
the index.php is served from the public_html directory.
The root directory remains inaccessible via HTTP. So
what you can do is to place your downloads directory
outside \public_html:

\ [Root directory]
\public_html
\downloads

Then your download script could do something like this:

header(''Content-Type: application/zip'');
readfile(''/downloads/somefile.zip'');

2. Protect the downloads directory by using an .htaccess file.

Your downloads directory can be located inside the
document root, but you can disable HTTP access to it
by putting an .htaccess file in that directory containing
the following directives:

Order allow,deny
Deny from all

Then your download script could do something like this:

header(''Content-Type: application/zip'');
readfile(''downloads/somefile.zip'');

Cheers,
NC


St *********** @ gmail.com 说...
我想让我的下载部分不可浏览(到用户)但是脚本可以访问。

我可以将文件传送到浏览器而不链接到它的URL,这样我就可以以编程方式传送文件但是阻止用户访问浏览或链接到他们?
I would like to make my downloads section unbrowsable (to users) but
accessible to scripts.

Can I deliver a file to a browser without linking to it''s URL so that I
can deliver files programmatically but prevent users from browsing or
linking to them?




绝对是。


将文件放在外面的目录中Apache文档根

(这意味着用户永远不能直接浏览网页)。 PHP可以在文件系统的任何地方(允许)访问
文件,而不仅仅是Apache的doc根目录中的目录。


快速和脏/ / somewhere/inside/docroot/download.php脚本:


<?php



Absolutely yes.

Put the files in a directory which is outside the Apache document root
(which means that users can never web browse directly to them). PHP can
access files anywhere on the file system (that it is allowed to), not just
the directories within Apache''s doc root.

Quick and dirty /somewhere/inside/docroot/download.php script:

<?php


filepath =''/ somewhere / outside / docroot /'';
filepath=''/somewhere/outside/docroot/'';


这篇关于以编程方式“交付”文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆