LARAVEL - How to share images between projects

Asked

Viewed 112 times

1

I have several projects Laravel on the same server. Often, I need to use employee photos and, as I have programmed, I copy the photos from the directory public/assets/images from an existing project to the same directory as the project being developed, causing a very large increase of repeated files. Is there any way to share photos between projects or have a common repository?

I saw that there is a feature in Laravel, which is the use of 'symbolick link', but I didn’t understand absolutely how to do.

Below, I make an example of the idea I’m trying to approach, not knowing if this is the way. The code is of the project under development, needing to pick up the path of the photo of another existing project, using the word pathFile as this note:

<tr>
  <td>
    <img src='+caminhoArquivo+'+retorno[i].foto+'" style="width:50%;height:auto;" />
  </td>
 </tr>

Would it be possible?

  • If you create a sub-domain pointed to that directory and use on other sites?

  • @Virgilionovic my problem, which must be really particular, is that I tried to refer to a common folder in the served using an absolute path, but, I don’t know if it is Laravel’s impediment, it never works. You always say the path doesn’t exist.

1 answer

1


Actually the Symbolic native Laravel link is for a directory mapping of a single project.

What you can do is create a default directory in your file structure, and make a symbolic link to this directory in a subfolder of storage/app of each of the projects, something like this:

mkdir /var/www/shared-files
cd /var/www/prj-1/storage
mkdir app/files
ln -s /var/www/shared-files/* app/files
cd /var/www/prj-2/storage
app/files
ln -s /var/www/shared-files/* app/files

And so on in each of the projects.

  • Ademir Mazer, I don’t know about Linux, but I follow his instructions like this: a) a folder named Shared-files is created and it will be there that the common files will be; b) the directory is changed to 'var/www/prj-1/Storage', (which I don’t know what it is); c) the folder 'app/files' is created in this directory; d) the folder that has the common files is mapped with the ln command. At this point, I did not understand what was the 'nickname' of the mapping. Besides, I am under Windows.

  • I went to Windows and saw how to create the 'Symbolic link'. In my case, the images that I wish to share are in c: xampp htdocs Public evaluation Assets images'. The directory of my project, where such images should be located is very similar: c: xampp htdocs Portable public persons Assets images. Then, I commanded at the Windows prompt of the server, as Administrator, the following: mklink /d "c: xampp htdocs Standard public persons Display remote image images" "c: xampp htdocs Standard public rating Assets images". In my project, I put 'imagem_remote' as path but gave 403 (Forbidden)

  • Continuing, 403 (Forbidden) is an Apache protection. I saw that I wanted to modify the httpd.conf file in the <Directory> block and, from what I understood, put there a permission for the symbolic link. I wrote there, half groping in the dark, <Directory "c:/xampp/htdocs/Laravel/rating/public/Assets/images"> Options Followsymlinks Allowoverride None Require all granted </Directory>, rescued, dropped Apache and raised again. I went to my new project, referenced the name of the symbolic link created (imagem_remote) and then it worked!

  • Glad you managed to hit Windows, I don’t use it and wouldn’t know how to detail the steps to the suggestion I proposed

Browser other questions tagged

You are not signed in. Login or sign up in order to post.