0

I have a mysql database which stores the paths of some images on a network drive.

I thought that using Ajax, I would be able to dynamically generate image tags to display these images in the browser as each image tag would inovoke a new GET request with the path relative to the browser.

The web server has a small HDD and I don't want to have to duplicate everything - so can't store large numbers of images on the server.

My PHP seems to generate the image tags correctly however the broswer does not show the images.

PHP code:

$sql = "SELECT ID,Link FROM tblStorePictures  WHERE StoreNumber = $sto";

$result = mysql_query($sql,$dblink) or die(mysql_error());
$row = mysql_fetch_array($result);

$id = $row['ID'];
echo "<img src='file://".$row['Link']."' alt='Image' id=$id>";

The image tags (as viewed in firebug) end up looking like this:

<img id="57" alt="Image" src="file://x:/Image1.jpg">

I have tried various things but nothing works:

  1. Dynamically generating the image tags with javascript using the document.createElement("img") method and setting attributes for the source etc.

  2. Using javascript to set innerHTML.

In all cases I've got the tags to generate correctly, but I still see nothing in the browser but the alt text.

Any suggestions welcome.

  • 2
    This might only work on a setup when viewing the file from your local computer, but I'm pretty sure apache does not support these type of image locations and they must be part of the wwwroot/www/public_html folder of your website. Only way this would work is by loading the image using PHP and displaying it afterwards. – Joshua - Pendo May 10 '11 at 13:26
  • Is "file://x:/Image1.jpg" a valid url? if you put that in your browser do you get the image? -- Do you assume all your client browser will have access to file://x: on their computers? – regilero May 10 '11 at 13:27
  • @regilero everyone on the network has the same drives mapped so all clients should be able to access the images. The URIs of the images are all valid. – user468562 May 10 '11 at 13:42
  • 1
    possible duplicate of [Firefox Links to local or network pages do not work](http://stackoverflow.com/questions/192080/firefox-links-to-local-or-network-pages-do-not-work) – AJ. May 10 '11 at 13:50
  • I think he/she is using a dreamweaver software which by default gives this file urls, and the user above does not know the difference between live, and local – Val May 10 '11 at 14:16
  • I'm not using dreamweaver, all the code I write myself. @PENDO, PHP cannot load the images as it's on a server that's on the network but does not have the network drive mounted. I was under the impression that the browser handled the request for each image and so as long as the destination in the SRC property could be reached by the client (using the file:// protocol) then the browser would download the images. It didn't originally but it seems to be working in IE now so maybe AJ's suggestion is correct. – user468562 May 10 '11 at 14:37
  • This is definitely related to the article AJ posted. I've encountered this on my own project, and had no luck with the "LocalLink" extension either. – Chris Baker May 10 '11 at 17:17

2 Answers2

1

What you are facing is a security feature of your browser. In fact, your browser will not follow links to local web pages (it means file:// urls) because the page you are viewing is not a local one (you are not at file://.../.../page.html). Therefore the browser sees a website on the network trying to access a file on your hard drive, and denies access to it for obvious reasons.

Joan Rieu
  • 999
  • 8
  • 19
  • Further investigation has shown this to be correct. I've added a few lines to user.js in firefox profile to allow it to work but all other browsers (apart from IE) won't allow it. Thanks for your help. – user468562 May 11 '11 at 08:34
0

It's not an issue with AJAX but an issue with the link to the file. I can almost guarantee your linking is wrong somehow. If you enter the exact link the the file "file://x:/Image1.jpg" in the url filed of the browser, and nothing shows up, it proves there's an issue with your file links.

Greg Thompson
  • 886
  • 4
  • 12
  • 31