473,503 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

deny direct access to a single folder with .htaccess

Hello,
I have not found a clear way of doing what I want and resort to posting
my question.

I have a php file that will link to pdf files from a directory called
pdf (within the apache htdocs folder). The way I have it coded now, the
address to the pdf shows in the address bar, and a user can modify just
the file name to read other files, which is something I don't want.
I am trying to deny access to this pdf directory to anyone except the
localhost, so that changing the file name will not allow viewing it. Is
this the proper way I should go about resolving the matter?
Is there a better way?

Thank you,
psion

P.S. I have tried what I think would be best, which is to display a pdf
file by "printing" it with the php file, ie:

$file_contents = file_get_contents('$filename');
header('Content-type: application/pdf');
print $file_contents;

but I get an error, stating that the pdf file can't be displayed
because it may be corrupt, and it isn't. Was anyone successful in doing
something like this?

Apr 19 '06 #1
2 4718
psion wrote:

P.S. I have tried what I think would be best, which is to display a pdf
file by "printing" it with the php file, ie:

$file_contents = file_get_contents('$filename');
header('Content-type: application/pdf');
print $file_contents;

but I get an error, stating that the pdf file can't be displayed
because it may be corrupt, and it isn't. Was anyone successful in doing
something like this?


The reason you get an error, is because you are trying to read the
content of the file named $filename, as opposed to the file named
whatever the variable $filename contains. Check up on the difference
between single ' and double " quotes. Another thing is that you
shouldn't be using quotes at all in this case. The line should read
something like this:

$file_contents = file_get_contents($filename);
--
Tommy Gildseth
http://design.twobarks.com/
Apr 19 '06 #2
Either way, without quotes or with quote (single or double), I seem to
end up with an error:

File does not begin with 'PDF%'

Searching for this on google does not point to solutions.

Apr 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4029
by: Jan Bols | last post by:
I'm using PHP 4.3 and APACHE2.0. I have a website that requires people to log in before they can download files from my website. A person is logged in if there is a session-variable $logged_in set...
2
1206
by: spike | last post by:
I tried to upload a .htaccess-file to the directory that i wanted to protect. This is what I wrote in it: ------------------------------------------------ <Limit GET> order deny,allow deny from...
3
2890
by: CJM | last post by:
I have a intranet-based system running IIS5/6. We have a secure logon feature whereby certain users can access restricted content. While most of this is ASP pages, and thus we can control that,...
7
3858
by: ABC | last post by:
How can I deny all users directly access image files from images folder?
2
5217
by: Tim::.. | last post by:
Hi can someone please tell me why this web.config file doesn't deny access to all for the folder it is in??? I have the web.config file in a folder called contents but for some reason I can...
5
10176
by: Nosferatum | last post by:
I am in need of a solution on how to solve this problem: I need to limit access to six different folders. My users are validated in a system which check their prescence with a couple of...
0
1133
by: ramakanaveen | last post by:
Hi , I have an applet like <Applet code="x.class" codebase="a.jar,b.jar" ...> The above a.jar and b.jar are in defaultwebapp folder of web application which is a public access folder, so...
0
6534
by: Jankie | last post by:
Good morning everyone Am hopeful that someone can share me some advice as to the best .htaccess example for a site under development. When i use something like this: <Limit GET POST> ...
3
2159
by: samvb | last post by:
Hi, I have a folder within my root website (cant move it out cos of restrictions). I have placed htaccess file in it which works just fine. It displays the usual log in box when someone tries to...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7458
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.