469,927 Members | 1,664 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

including image, js, css from private dir

hello, here is my dir structure:

/private
mainaction.php
img.jpg

/public_html
index.php

in index.php, I include mainaction.php. In mainaction.php, i want to
have
<img src='<?php insertImageHere ?>' > and have img.jpg show in
index.php. I need to do this for a .js file and a .css as well. The
js and css I could easily enough just echo it to the page. (but they
would make my page messy while I'm debugging)

the idea is to have everything in the private dir, and have multiple
sites on my server use the code and the images.

now that I type this, I realize that I could set up a central public
site for the img css js, and use absolute links...

hints, ideas, shoves in right directions appreciated,

--
thanks for your time,
juglesh

Nov 6 '05 #1
6 2060
juglesh said the following on 06/11/2005 18:28:
hello, here is my dir structure:

/private
mainaction.php
img.jpg

/public_html
index.php

in index.php, I include mainaction.php. In mainaction.php, i want to
have
<img src='<?php insertImageHere ?>' > and have img.jpg show in
index.php.


If the image file is in a private directory, it can't be accessed by the
outside world, hence it can't be seen in a browser...
--
Oli
Nov 6 '05 #2

Oli Filth wrote:
juglesh said the following on 06/11/2005 18:28:
hello, here is my dir structure:

/private
mainaction.php
img.jpg

/public_html
index.php

in index.php, I include mainaction.php. In mainaction.php, i want to
have
<img src='<?php insertImageHere ?>' > and have img.jpg show in
index.php.


If the image file is in a private directory, it can't be accessed by the
outside world, hence it can't be seen in a browser...


not directly, no, but can i do some thing with header() etc.? I tried
<img src='<?php include 'image.php' ?>' >
I got a 404

Nov 6 '05 #3
juglesh wrote:
not directly, no, but can i do some thing with header() etc.? I tried
<img src='<?php include 'image.php' ?>' >
I got a 404


That'll simply print the contents of image.php into the src='' tag. Not
what you want. Try viewing your HTML sourcecode once in a while to check
for things like this.

Cheers,
Nicholas Sherlock
Nov 7 '05 #4
juglesh (ju*********@hotmail.com) wrote:

: Oli Filth wrote:
: > juglesh said the following on 06/11/2005 18:28:
: > > hello, here is my dir structure:
: > >
: > > /private
: > > mainaction.php
: > > img.jpg
: > >
: > > /public_html
: > > index.php
: > >
: > > in index.php, I include mainaction.php. In mainaction.php, i want to
: > > have
: > > <img src='<?php insertImageHere ?>' > and have img.jpg show in
: > > index.php.
: >
: > If the image file is in a private directory, it can't be accessed by the
: > outside world, hence it can't be seen in a browser...

: not directly, no, but can i do some thing with header() etc.?

No.

The file must be in an accessible place.

You mentioned having a public directory with links to the "real" copy of
each "private" file. That technique would work.

OR - consider _copying_ the private file to the public location. That way
you can edit a private copy ahead of time and then "publish" it when ready
(by copying to the public area). That might be more secure as there would
be less that could go wrong to allow the web server to serve anything not
in the public area. ($0.10)
--

This programmer available for rent.
Nov 7 '05 #5

Malcolm Dew-Jones wrote:
juglesh (ju*********@hotmail.com) wrote:

: Oli Filth wrote:
: > juglesh said the following on 06/11/2005 18:28:
: > > hello, here is my dir structure:
: > >
: > > /private
: > > mainaction.php
: > > img.jpg
: > >
: > > /public_html
: > > index.php
: > >
: > > in index.php, I include mainaction.php. In mainaction.php, i want to
: > > have
: > > <img src='<?php insertImageHere ?>' > and have img.jpg show in
: > > index.php.
: >
: > If the image file is in a private directory, it can't be accessed by the
: > outside world, hence it can't be seen in a browser...

: not directly, no, but can i do some thing with header() etc.?

No.
or with some file_get_contents thing. For instance, you can turn an
image into a string of text and spit it out. Not sure how compatible
this is.
The file must be in an accessible place.

You mentioned having a public directory with links to the "real" copy of
each "private" file. That technique would work.


Yeah, I'm just going with serving the images and .js from a public dir.
The css I couldnt make work with FF, @import worked fine with IE. I'm
just echoing the css straight to the page now.

--
thanks all!
juglesh

Nov 8 '05 #6

juglesh wrote:
hello, here is my dir structure:

/private
mainaction.php
img.jpg

/public_html
index.php

in index.php, I include mainaction.php. In mainaction.php, i want to
have
<img src='<?php insertImageHere ?>' > and have img.jpg show in
index.php. I need to do this for a .js file and a .css as well.


Ok, this turned out to be an Apache question. You need to use an Alias
to tell apache what dir to look in, despite what the browser is asking
for. And, <Directory> to allow the access. The following code goes in
apache's httpd.conf config file, in my case, under the line that says
<IfModule mod_alias.c>

Alias /test/ "c:/my documents/_websites/guava/private/test/"

<Directory "c:/my documents/_websites/guava/private/test">
Order allow,deny
Allow from all
</Directory>

That will make it so <img src='/test/image.jpg' > gets the image from
the private dir, not from a folder in the web root. Works for .js,
..css, whatever.

--
j

Nov 25 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by JF Turcotte | last post: by
4 posts views Thread by moondaddy | last post: by
4 posts views Thread by tshad | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.