你好,我是新来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表格,我们只是定义了列。请帮助我。谢谢你在前进
这是我的看法对文件单击虽然...也许在这里做一些错误的,但我不这么认为,但以防万一... ' {{ $upload['file_name'] }}' –
添加'其他{... }'if(File :: isFile($ file_name){}''后面的块会返回一个关于找不到文件的错误响应,看看是否返回错误(表示文件不存在) – Matey
我刚刚添加了'else { Session :: flash(“message”,“File Not found”); return redirect(“\ home”); }' 并且它显示“文件未找到” –