including image, js, css from private dir

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • juglesh

    #1

    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

  • Oli Filth

    #2
    Re: including image, js, css from private dir

    juglesh said the following on 06/11/2005 18:28:[color=blue]
    > 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.[/color]

    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

    Comment

    • juglesh

      #3
      Re: including image, js, css from private dir


      Oli Filth wrote:[color=blue]
      > juglesh said the following on 06/11/2005 18:28:[color=green]
      > > 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.[/color]
      >
      > 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...[/color]

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

      Comment

      • Nicholas Sherlock

        #4
        Re: including image, js, css from private dir

        juglesh wrote:[color=blue]
        > not directly, no, but can i do some thing with header() etc.? I tried
        > <img src='<?php include 'image.php' ?>' >
        > I got a 404[/color]

        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

        Comment

        • Malcolm Dew-Jones

          #5
          Re: including image, js, css from private dir

          juglesh (jugleshjunk@ho tmail.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.

          Comment

          • juglesh

            #6
            Re: including image, js, css from private dir


            Malcolm Dew-Jones wrote:[color=blue]
            > juglesh (jugleshjunk@ho tmail.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.[/color]

            or with some file_get_conten ts thing. For instance, you can turn an
            image into a string of text and spit it out. Not sure how compatible
            this is.
            [color=blue]
            > 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.[/color]

            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

            Comment

            • juglesh

              #7
              Re: including image, js, css from private dir


              juglesh wrote:[color=blue]
              > 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.[/color]

              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

              Comment

              Working...