Spiral's avatar

How can i Preview uploaded ppt file in brower

I have uploaded a ppt & ppt file in Laravel and now I want to show a preview of this ppt file on click. Now when I click on ppt file then this is force downloading

I'm using this code but getting not better results

public function view($file_name){
        if($file_name) { 
            $file = storage_path('app/public/files/' . $file_name); 
            if (file_exists($file)) {
                $ext = File::extension($file);
                if($ext == 'pdf'){
                    $content_types = 'application/pdf';
                } elseif ($ext == 'doc') {
                    $content_types = 'application/msword';  
                } elseif ($ext == 'docx') {
                    $content_types = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';  
                } elseif ($ext == 'xls') {
                    $content_types = 'application/vnd.ms-excel';  
                } elseif ($ext == 'xlsx') {
                    $content_types = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';  
                } elseif ($ext == 'txt') {
                    $content_types = 'application/octet-stream';  
                } elseif ($ext == 'pptx') {
                    $content_types = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';  
                } elseif ($ext == 'ppt') {
                    $content_types = 'application/vnd.ms-powerpoint';  
                }

                return response(file_get_contents($file),200)->header('Content-Type', $content_types);
            } else {
                return 'Requested file does not exist on our server!';
            }
        } else {
            return 'Invalid Request';
        } 
    }

and the second option I'm using this but not getting also results in the blade file

<iframe src="https://docs.google.com/viewer?url={{storage_path('app/public/files/' . $file->name)}}&embedded=true" frameborder="0" style="width: 62%; min-height: 562px;"></iframe>
0 likes
0 replies

Please or to participate in this conversation.