Hi all,
I am working on a PHP project. Im having a problem giving the 'src' for a image, because the image file is placed outside of the www folder :(.

Let me explain more.

When I log in to my server using FTP logins, it gives the directory structure as below

+--www
+--project1
-----+www
----------index.php
-----+resources
--------+additional
---------------image.jpg
+--oldproject
+(some other folders)

I can access my project1 directly through the browser using
http://hostname/index.php
That means /project1/www/index.php file directly get executed by calling http://hostname/index.php (I really don't know how it is done, but it's working :))

Now I want to use project1/resources/additional/image.jpg for a <img> tag in /project1/www/index.php file.

I tried, <img src="../resources/additional/image.jpg"> But it's not woring :(

Can anybody help me with this please...?

Thank you so much for spending time to read this

Cheers
Niranga

My guess is that you're using the first www folder not the www folder that lies under the "project1" folder

so I guess you should try:
../project1/resources/additional/image.jpg

Hi theighost,

Thanks a lot for the reply..!!!
Actually I tried that too... but it didn't work :(

To check which www folder is been used, I did some changes to www/index.php( wrote a single line to print "test"), but nothing happened.
So again I put the same line of code into the /project1/www/index.php and it printed that line

Please help me out.
This project originally done by another developer and now i can't contact him :(

Cheers Niranga

hello,

Try echoing "$_SERVER" and see where is the page exactly..

if the image was in the correct place and the .php file was in the correct place too, then "../resources/additional/image.jpg" would work no doubt about that.

Hi,
So Sorry for taking so much time to reply.

$_SERVER gives me this
/home/users/web/b562/whl.aunn2008/project1/www/

So as the FTP client displays the folder structure the image should be placed in /home/users/web/b562/whl.aunn2008/project1/resources/additional/image.jpg

Still ../resources/additional/image.jpg does not displays the image :( :( :(

Niranga

could you check if the image is there..

Why don't you just move the folder? lol

Also, I may be wrong, but can't you use multiple .. 's? So something like this..


../../../folder/file.txt

Hiii,

@theighost: Yes I double checked it. Unfortunately image is there.... :)

@CodeEgg: Yes, if i could move the folder it will be great, but the poblem is that folder is been used by some other functions also :(. I tried using multiple '../' too. but no luck.

If http://sitename.com/ refers directly to the www folder, is it possible to refer another folder which placed outside of the www folder(in same level) ?

For an example let's say http://sitename.com/index.php file contains a link like below. <a href="help.html">HELP</a> When I move my mouse pointer over it, i can see the destination address as http://sitename.com/help.html

If I insert the following link, <a href="../resources/temp.html">TEMP</a> and move my mouse pointer over it, i get the destination address as http://sitename.com/resources/temp.html

So does that mean, '../' do not go out from the www? :( :(

Cheers
Niranga

Hi,
So Sorry for taking so much time to reply.

$_SERVER gives me this
/home/users/web/b562/whl.aunn2008/project1/www/

So as the FTP client displays the folder structure the image should be placed in /home/users/web/b562/whl.aunn2008/project1/resources/additional/image.jpg

Still ../resources/additional/image.jpg does not displays the image :( :( :(

Niranga

OK, by what you've said, the webserver is serving pages from your site out of this folder:

/home/users/web/b562/whl.aunn2008/project1/www/

So, anything OUTSIDE that folder will not be visible to your web browser. It sounds like you want to move the resources folder into this www directory, so the full path to the image will be:

/home/users/web/b562/whl.aunn2008/project1/www/resources/additional/image.jpg

And for your web browser the path would be:

http://sitename.com/resources/additional/image.jpg

If you want to keep the images in this other folder, you'll need to use server side scripting of some kind to include the image in your page.

-----------------------------------------------

After reading the rest of the thread, I see that you can't move the images. So, there's probably some function that is serving the images already that you can use, or write your own, something like this:

In a file called "image.php":

<?php

$file = basename(urldecode($_GET['file']));
$fileDir = '/home/users/web/b562/whl.aunn2008/project1/resources/additional/';

    if (file_exists($fileDir . $file))
    {
        // Note: You should probably do some more checks 
        // on the filetype, size, etc.
        $contents = file_get_contents($fileDir . $file);

        // Note: You should probably implement some kind 
        // of check on filetype
        header('Content-type: image/jpeg');

        echo $contents;
    }
?>

In the index.php file:

<img src="image.php?image.jpg">

Hi genevish,

Thanks a lot for your reply sir. I will try the code you posted and get back to you as soon as possible..

Thanks again..!!!

Cheers
Niranga

Hi genevish,

Thaks a lot genevish....!!!! :) :) :) :)

Its working...!!!!
Great solution..!!!! Thanks a lot...!!! I really appreciate it..

Thanks again..

Cheers...!!!!!
Niranga

Good Knowledge keep it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.