2015-12-24 12 views
5

के साथ बल डाउनलोड फ़ाइल तो मैं लैरवेल 5 का उपयोग कर रहा हूं और मैंने एक चयनित फ़ाइल डाउनलोड करने के लिए मजबूर करने की कोशिश की लेकिन कुछ भी नहीं हुआ।लारवेल

public function downloadUserFile(){ 
     $result = $_POST['filename']; 
     $entry = File::where('filename', $result)->firstOrFail(); 
     $file = Storage::disk()->get($entry->filePath); 
     $headers = array('Content-Type' => $entry->mimetype); 
     return response()->download(storage_path($entry->filePath), $result, $headers); 
} 

और प्रतिक्रिया हेडर ठीक होने लगते हैं

Accept-Ranges: none 
Cache-Control: public 
Connection: Keep-Alive 
Content-Disposition: attachment; filename="SIGNAL - Nadezdata.mp3" 
Content-Length: 4205059 
Content-Type: audio/mpeg 

क्या आप जानते हैं कि क्या गलत है?

उत्तर

1

मुझे लगता है कि समस्या पथ में है।

config/filesystems.php स्थानीय पथ में डिफ़ॉल्ट रूप से इस तरह से परिभाषित किया गया है: storage_path('app') और आप डाउनलोड में पारित निम्नलिखित पथ: storage_path($entry->filePath) (कोई app यहाँ शामिल)।

आपको क्या करना चाहिए बदल रहा है:

return response()->download(storage_path($entry->filePath), $result, $headers); 

में:

return response()->download(storage_path('app/'.$entry->filePath), $result, $headers); 
+0

मैं पहले से ही यह बदल दिया है। लेकिन मैंने दृश्य में कुछ भी नहीं पारित किया है। क्या यह समस्या हो सकती है? – Alex

+0

आपका क्या मतलब है? आप फ़ाइल को डाउनलोड करने के लिए सरल बल ब्राउज़र पर क्लिक करने के बाद, यहां किसी भी दृश्य का उपयोग नहीं करते हैं और यह –

+0

है लेकिन कुछ भी नहीं होता है। कोई बल डाउनलोड नहीं है – Alex

संबंधित मुद्दे