Reputation: 7138
I am trying to show attached documents to users and as attachments are mostly files not photos such as zip
pdf
docx
i want to show static images regarding to type of those attachments but i get this error
mime_content_type(): Can only process string or stream arguments
Note: I am using Laravel PHP Framework and this validation is happening in blade template
Code
@if(mime_content_type('images/'.$document->file == 'application/zip'))
<img src="{{url('img')}}/zip.jpg" alt="zip file" class="img-fluid">
@elseif(mime_content_type('images/'.$document->file == 'application/pdf'))
<img src="{{url('img')}}/pdf.jpg" alt="pdf file" class="img-fluid">
@elseif(mime_content_type('images/'.$document->file == 'application/msword'))
<img src="{{url('img')}}/docx.png" alt="docx file" class="img-fluid">
@elseif(mime_content_type('images/'.$document->file == 'image/jpeg'))
<img src="{{url('img')}}/jpeg.png" alt="jpeg file" class="img-fluid">
@elseif(mime_content_type('images/'.$document->file == 'image/png'))
<img src="{{url('img')}}/png.png" alt="png file" class="img-fluid">
@else
<img src="{{url('img')}}/unknown.png" alt="unknown file" class="img-fluid">
@endif
PS: If I use this code for instance
{{dd(mime_content_type('images/'.$document->file) )}}
I will get
"application/zip"
Any idea?
Upvotes: 0
Views: 4558
Reputation: 346
@if(mime_content_type('images/'.$document->file == 'application/zip'))
you should use this (look at parentheses): Your code is returning bool not a string
@if(mime_content_type('images/'.$document->file) == 'application/zip')
Upvotes: 2
Reputation: 50541
mime_content_type('images/'.$document->file == 'application/zip')
You probably don't want to be doing an equality check on those 2 strings in the function call.
'images/'.$document->file == 'application/zip'
false
So you are basically taking the long way to write:
@if (mime_content_type(false))
Upvotes: 1