How to access and display the images that are located outside the application folder? Let’s say I have a file directory that stores all the images and other file types, and this file directory is located on a different drive then my application folder. For certain file types ( such as .pdf, .doc, I want to prompt the user to download those files).
As far as I know, it’s not possible to put absolute path in the <img src attributes, i.e, img src="D:\\file directory"> doesn’t work. And also I want to restrict the access to login user only.
I am using PHP as my server side language.
Note: <img src="file:/// .../> won’t work in Firefox. See here for comments.
Edit: Since only authenticated user can access those images, and since I have an index.php that checks for all the incoming requests, filters off non-authenticated users, I don’t think creating an Apache Alias will work.
Here’s an example of my conf file:
NameVirtualHost *:80
<VirtualHost *:80 >
ServerName pmmenu.businessjob.net
DocumentRoot "D:\web"
DirectoryIndex index.html index.php
<Directory "D:\web">
AddDefaultCharset UTF-8
Order Deny,Allow
Allow from all
RewriteEngine on
RewriteBase /
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</Directory>
</VirtualHost>
I think you’re missing a basic concept here. All HTML is interpreted client-side. Every image is downloaded seperately by the browser of your visitor. As your visitors can only access those files that are public, “file:///something” will not work for them, because this asks their browser to access the local (their) filesystem, which will either be blocked or not find the requested image as it is not stored on their disk.
So you will have to publish those pictures and make them accessible via http to allow your visitors to see them. You could do this by creating a subdomain or a virtual directory.
Since you want only authenticated users to be able to see them, you could also create a php file that checks whether the user is authenticated, e.g. like this:
But you have to be aware that this script will always read the whole image and print it subsequently, which is a huge overhead.