views:

392

answers:

4

I'm using Apache and Windows and I'm writing an application that needs to display the images of parts that are on a different server, not in the path of the application directory. There are too many images to move and other applications use these same images.

What is the best way to deal with this problem?

The back end is php and myslq - though I don't think that's relevant.

Thanks

A: 

Have you looked at symbolic links?

ln -s LocalName FullPathOfRealFileLocation
Rap
yes, I tried that. That would work well in any of the unix/linux variants. Window shortcuts can't be used in middle of path names.ie images/shortcutToAnotherFolder/image.jpg doesn't work in windows.
sdfor
A: 

Since the images are on a server, why not reference them directly in your code ?

<img src="http://myotherserver.com/images/picture.jpg"
sjobe
thanks for the thought. The other server is not accessible via the internet it's on an accounting server
sdfor
+1  A: 

if your files are stored outside the www root. then, you'll need to have enough permissions to access to the files.

Then, you could do something like :

<?php

$imageFileName = $_GET['image'];
$path = '/var/data/somewhere/';

$fullpath = $path . $imageFileName;

if (!is_file($fullpath))
{
   die('Image doesn't exist);
} else {
   $size = filesize($fullpath);
   $content = file_get_contents($fullpath);
   header("Content-type: image/jpeg");
   echo $content;
}

Well, don't use this code in a production environement, since it's NOT SECURE.

You can use getimagesize() to check if it's an image. Blacklist the phps extensions, etc... Specify a working directory, to don't be able to use the backward ../../

file_get_contents()

EDIT :

About your comment about the symbolic link, if you have access to apache.conf file, you can specify an alias which points to another directory outside your webroot.

Boris Guéry
A: 

The best answer that I've discovered if your using Apache. which I am, is to use the Apache Alias feature, to allow access to an internal directory.

As suggested by the answer from BGY above.

I added the following to http.conf:

Alias /fabimages p:/IMDATA/IMAGES
<Directory p:/IMDATA/IMAGES>
    Order allow,deny
    Allow from all
</Directory>

in my code I set the .src attribute to the image I need:

var fabimage = document.getElementById("fabImageTag");
fabimage.src="/fabimages/"+imageName; // and it picks up the image from p:/IMDATA/IMAGES
sdfor