2

If i want to view pdf, docx, doc, zip rar and others document in same view page. what should i do?

description: If user upload a pdf file its need to show pdf and if user upload a doc file its need to show doc. any solution please.

My view

@if($status->type == 1)
      <a href="{{ $status->image_url }}"></a>
         <img src="{{asset('status_images/'.$status->image_url)}}" class="img-responsive" style="width:100%;">

     @endif
Shuvo
  • 273
  • 2
  • 7
  • 23

3 Answers3

4

You can use iframes to preview documents in your page. Simply provide the source of the document in the iframe src. You can use this method to preview pdf and document files. Now, Since browsers directly do not have integrated viewers for documents, you can use https://view.officeapps.live.com to preview Word, Excel, or PowerPoint document (as per the website). So, you can simply

 @if(upload is image)
   <img src="{{image url}}"/>
 @elseif(upload is pdf)
   <iframe src="{{pdf url}}" frameborder="0" style="width:100%;min-height:640px;"></iframe>
 @elseif(upload is document)
   <iframe src="https://view.officeapps.live.com/op/view.aspx?src={{urlendoe(doc url)}}" frameborder="0" style="width:100%;min-height:640px;"></iframe>
 @else
   //manage things here
 @endif

If you want to preview zip and RAR files, check this out In PHP is it possible to inspect the content of a Zip file without extracting its content first? . I personally have not used this, but, yeah this might help.

Mohamed Mo Kawsara
  • 4,400
  • 2
  • 27
  • 43
Wdy Dev
  • 219
  • 2
  • 11
0

You can see PDF or image files with the integrated viewer that has the web browsers, but you can't do this with all formats. Some formats, like zip, rar,... must be downloaded to the desktop, tablet or mobile phone and viewed with the corresponding program.

Jesús Amieiro
  • 2,443
  • 21
  • 15
  • How can i use integrated viewer?? – Shuvo Jul 29 '16 at 21:03
  • The integrated viewer is integrated and it depends on your web browser (or your end user web browser), so you can't rely on an integrated viewer that can change from one web browser to another (v.gr. from Google Chrome to Mozilla Firefox or Microsoft Edge). – Jesús Amieiro Jul 29 '16 at 23:47
0
<iframe src="https://view.officeapps.live.com/op/view.aspx?src={{url("https://file-examples.com/wp-content/uploads/2017/02/file-sample_100kB.doc")}}" frameborder="0" style="width: 62%; min-height: 562px;"></iframe>
  1. Offical office live helps to render files in iframe.
  2. Above is the example to render dummy doc file.
  3. Don't forget to use a live url for document instead of local
  4. Copy paste & you are good to go.
Community
  • 1
  • 1
Akashxolotl
  • 428
  • 5
  • 6