LoginSignup
0
0

More than 3 years have passed since last update.

How to make a file URL copy button (File Upload Site #2)

Posted at

今回はファイルダウンロードリンクをコピーするボタンを作ります。
1.Route

web.php
Route::get('files/uploadedfiles/{name}', 'FilesController@copy')->name('copyfile');

2.ボタン

home.blade.php
<input value="{{ route('copyfile', $file->id)}}" id="copy_{{ $file->id }}" type="text">
<button value="copy" class="btn btn-link" onclick="copyToClipboard('copy_{{ $file->id }}')">Copy!</button>

3.Controller App->Http->Controllers->FilesController.php に

FilesController.php
public function copy($url)
    {
        return Storage::url('/files/uploadedfiles/' . $url->name);
    }

4.Javascript を view ファイルに入れる

home.blade.php
function copyToClipboard(id) {
                document.getElementById(id).select();
                document.execCommand('copy');
            }

Screen Shot 2020-07-26 at 13.10.12.png

以上です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0