Access to files through PHP with an alias to the directory in the apache

0

I have two domains that share a directory (example: / img) so as not to duplicate that directory I have created an alias with the apache:

Alias / img /dominio_1.com/img/ ....

from the browser I access the img directory without problems

www.dominio_2.com/img/imagen.jpg

but from php I can not access that file

$img = file_get_contents('/img/imagen.jpg');

Warning ... failed to open stream: No such file or directory

I guess it will be a matter of permits, but I still have not found a solution

    
asked by Carlos Garcia 20.10.2016 в 11:04
source

1 answer

1

An apache alias affects web browsing, but not the path of the files. To access the contents through the file system, try creating a symbolic link from the domain_1 folder in domain_2

ln -s {rutaDirectorioOrigen} {rutaDirectorioDestino}

Or you can access the files through your url as follows

$img = file_get_contents('http://midominio_2.com/img/imagen.jpg');

This way you do not need to create anything at the file system level, but you will have to enable the php configuration to allow you to do it. Specifically, the option allow_url_fopen

    
answered by 20.10.2016 в 11:31