Results 1 to 3 of 3

Thread: Display images outside the public folder with Layout

  1. #1
    kaybee is offline Junior Member
    Join Date
    Sep 2011
    Posts
    3

    Default Display images outside the public folder with Layout

    Cannot display images outside public folder

    Hi,

    I am trying to dynamically display images from an image store outside the public directory. I can ONLY display the image with the following code in the controller:

    1. $this->_helper->layout->disableLayout();
    2. $this->_helper->viewRenderer->setNoRender();

    3. $image = file_get_contents($filename);
    4. $this->getResponse()->clearBody ();
    5. $this->getResponse()->setHeader('Content-Type', 'image/jpeg');
    6. $this->getResponse()->setBody($image);



    BUT this means my elaborate Layout gets thrown out of the window (lines 1 & 2) and I just get the image on the page. How can I get the layout and the image and the layout to display?

    My directory structure is:

    -application
    ---modules
    -catalog
    -controllers
    -ImageController
    -models
    -views
    -scripts
    -image (display.phtml)
    -library
    -zend
    -public
    -imagestore
    -product1
    -img1.jpg
    -img2/jpg
    -product2
    -tests



    Thank you in advance!

  2. #2
    kaybee is offline Junior Member
    Join Date
    Sep 2011
    Posts
    3

    Default

    The directory structure again:

    -application
    ---modules
    -----catalog
    -------controllers
    ------------ImageController
    --------models
    --------views
    --------------------scripts
    --------------------image (display.phtml)
    -library
    ---zend
    -public
    -imagestore
    ----------product1
    ------------img1.jpg
    ------------img2/jpg
    ----------product2
    -tests

  3. #3
    kaybee is offline Junior Member
    Join Date
    Sep 2011
    Posts
    3

    Default The solution

    I finally figured this one out. I took the following two steps to make this work for me:

    STEP 1:
    Added an alias in the httpd-vhosts.conf file as shown below (without the quotes). For a non-virtual host situation you add it to the httpd.conf file.

    'Alias /ashortname "/path/to/external/physical/directory"
    <Directory "/path/to/external/physical/directory">
    Allow from all
    </Directory>'

    You could limit the "all" permission if you like. The path to the external physical dirctory based on my directory structure

    above would be "C:/vhosts/sitename/imagestore" on my Windows PC.

    STEP 2:
    In the view file ...which in my case is display.phtml I added (without the quotes):

    '<object width="400" height="400" type="image/jpeg" data='/ashortname/myimage.jpg'>

    </object>'

    I used the alias to find the image file to display via the object tag.

    That was it. This fixed the problem of displaying an image from a directory outside the site document root.

    Let me know if you have comments or other suggestions.
    Last edited by kaybee; 09-06-2011 at 10:23 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •