0

In my Laravel application, I want my backend controller to start a download for the user with a different web address (i.e. another domain and not Laravel). For the internal storage, I know how to properly start a download, but how if I only have the direct link (for instance: https://xy.tld/web/image1.png) without 'leaving' the Laravel instance (the current window shall not be altered)?

EDIT: I found this (Download a file in Laravel using a URL to external resource) and I don't want to download it to my laravel ere sending it to the user. However, someone there mentioned redirects. Can I redirect in a different window/tab?

Johnny
  • 272
  • 2
  • 15

2 Answers2

0

You could use something like file_get_contents() to get the file from the other server. This would lead to unneccessary traffic though because server 1 would download the file from server 2. That applies also to scp etc.

You should think about encryption:

$hash = encrypt([
    'valid_to' => strtotime('+30 minutes'),
    'file_path' => '/home2/alihoss1/domains/alihossein.ir/public_html/dl/video/MySql/Sql1.mp4'
]);

return redirect('http://server2.example/download/hash/' . urlencode($hash));

You then need to decrypt this on the second server with the same key. If you do not have laravel installed there, you can implement your own decrypting functionality (see: laravel openssl encryption).

0

Use download Attribute

<a href="https://www.google.ca/logos/doodles/2018/doodle-snow-games-day-1-4597519198715904.3-s.png" download> Download </a>