2016-09-23 58 views
1

你好,我是新来laravel和仍然在学习它,我遇到不同的困难和问题,我不能找到一种方法来解决它。我很久以来一直坚持这一点。任何帮助将非常感激。显示我的空白页上载的.docx文档时,在网站上laravel

的问题

每当我上传.docx文件到我的网站,我得到了一个空白页面没有任何错误或不具有的docx文件的内容。我不知道问题是什么。这个你能帮我吗。

代码

public function getUploadedFile() { 

    // $destinationPath = 'uploads'; 
    // $path= public_path()."/". $destinationPath; 

    // $content = utf8_encode(File::get('/var/www/html/asad/File-Uploader/public/uploads/detailed_period_report_template.xls')); 
    // return view('/files', compact('path')); 


    $file = $this->request->file('file_name'); 
    $file_name = $this->request->file_name; 

    if (File::isFile($file_name)) 
    { 
     $file_name = File::get($file_name); 
     $response = Response::make($file_name, 200); 
     $content_types = [ 
      'application/octet-stream', // txt etc 
      'application/msword', // doc 
      'application/vnd.openxmlformats-officedocument.wordprocessingml.document', //docx 
      'application/vnd.ms-excel', // xls 
      'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', // xlsx 
      'application/pdf', // pdf 
     ]; 
     // using this will allow you to do some checks on it (if pdf/docx/doc/xls/xlsx) 
     $response->header('Content-Type', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'); 

     return $response; 
    } 

我没有这方面的任何观点。我需要一个吗?如果是的话,会是什么样子,因为每个docx文件都有一组属性,如字体,大小等,而不像excel表格,我们只是定义了列。请帮助我。谢谢你在前进

+0

这是我的看法对文件单击虽然...也许在这里做一些错误的,但我不这么认为,但以防万一... '​​ {{ $upload['file_name'] }}' –

+0

添加'其他{... }'if(File :: isFile($ file_name){}''后面的块会返回一个关于找不到文件的错误响应,看看是否返回错误(表示文件不存在) – Matey

+0

我刚刚添加了'else { Session :: flash(“message”,“File Not found”); return redirect(“\ home”); }' 并且它显示“文件未找到” –

回答

0

我已经想通了后这么久终于。

有人发出“空”为使我做了什么,现在是从数据库中,而不是存储得到了文件名,然后进行了比较,如果该文件是存储和数据库,然后打开它的文件名。下面是现在为我运行的代码。 谢谢@MATEY所有的帮助,虽然

 $upload = new Upload; 

     $file= public_path(). "/uploads/" . $upload->file_name = $this->request->file_name; 
     //dd($file); 

     $files = File::get($file); 
     $response = Response::make($files, 200); 

,并改变了内容类型$response->header('Content-Type', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document');

谢谢你的所有帮助@MATEY。你给我动力修复它,加上你的else{...}部分缺失if条件实际上帮助我很多发现错误。