T
T
TonyStark13372022-03-12 21:27:13
PHP
TonyStark1337, 2022-03-12 21:27:13

Getting photo by Laravel + Vue token?

The task is to display photos only to authorized users by JWT token. Did this

public function render(Request $request) {
        Validator::make($request->all(), [
            'id' => 'required'
        ])->validate();

        $dataImg = ImgModel::get(array('id' => $request->id));
        $file = Storage::get('private/'.$dataImg['location']);
        $fileUrl = Storage::path('private/'.$dataImg['location']);
        header('Content-Type: ' . $dataImg['format']);
        echo file_get_contents($fileUrl);
    }


// vue

<img v-auth-image="https://domain.com/api/img/render/?id=30">

// не выводит фото

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2022-03-12
@ThunderCat

1) what's in the logs?
2)

echo file_get_contents($fileUrl);
Firstly, you need to check what is in $fileUrl, and secondly, readfile() is used for this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question