你好,我是新來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」); }' 並且它顯示「文件未找到」 –