How to access images in a directory outside of a web application

I use Apache and Windows, and I am writing an application that should display images of parts located on another server, and not on the application directory path. Too many images to move, and other applications use the same images.

What is the best way to solve this problem?

The back end is php and mysql - although I don't think it matters.

thanks

+3
source share
4 answers

if your files are stored outside the www root directory. then you will need to have sufficient permissions to access the files.

Then you can 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;
}

, , .

getimagesize(), , . php ..... , .. /../

file_get_contents()

:

, apache.conf, alias, -.

+2

?

ln -s LocalName FullPathOfRealFileLocation
0

, ?

<img src="http://myotherserver.com/images/picture.jpg"
0

The best answer I found if you are using Apache. which I am is to use the Apache Alias ​​function to allow access to the 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 for the image I need:

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

Source: https://habr.com/ru/post/1716643/


All Articles