【发布时间】:2017-02-01 01:01:20
【问题描述】:
你好,我是 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 工作表不同。请帮帮我。提前谢谢你
【问题讨论】:
-
这是我点击文件的观点……这里可能做错了什么,但我不这么认为,但以防万一……
<td><a href="/open-uploaded-file"> {{ $upload['file_name'] }} </a></td> -
在
if (File::isFile($file_name){ }之后添加一个else{ ... }块,您将在其中返回有关找不到文件的错误响应。看看这是否返回错误(意味着文件不存在)。 -
是的,我刚刚添加了
else { Session::flash("message", "File Not found"); return redirect("\home"); },它说“找不到文件” -
所以你有你的罪魁祸首。您需要确保知道文件的存储位置。
-
我知道文件的存储位置,但我没有办法给它提供该路径以便它可以提取文件。如果您在代码中看到第三行,那是我在尝试了所有可能的可能性后注释掉的文件的路径。我尝试取消注释并执行此操作,但仍然找不到相同的空白页或路径