Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the content of the file in variable in Laravel 5.5

I am uploading files that I need to attach to email via office365 API.

What I need is the content of the file in a variable WITHOUT storing/saving the file, how can I do that?

foreach ($request->filesToUpload as $file) {
    $originalName = $file->getClientOriginalName();//working
    $content = $file->getContent();//<- I need this, but not working
    //$this->addAttachment($content, $originalName) //logic for later
}
like image 330
Syed Waqas Bukhary Avatar asked Dec 13 '22 17:12

Syed Waqas Bukhary


1 Answers

Access the contents of the file like so:

$content = file_get_contents(Input::file('nameAttribute')->getRealPath());

or in other words inside that loop

$contents = file_get_contents($file->getRealPath());

Get the real path with object methods, and you may interact with it like any other file.

like image 143
sorak Avatar answered Dec 17 '22 22:12

sorak