2013-02-03 75 views
1
public function get_download($record_id) 
{ 
    $record = Record::find($record_id); 
    $file_name = $record->with_value('File Upload')->name; 

    // something like https://s3.amazonaws.com/webapp/uploads/laravelsauce.png 
    $file_url = read_file($record->with_value('File Upload')->value); 

    return Response::download($file_url, $file_name); 

    /* 
    // works but why not the above 
    header('Content-Type: application/octet-stream'); 
    header("Content-Transfer-Encoding: Binary"); 
    header("Content-disposition: attachment; filename='{$file_name}'"); 
    readfile($file_url); 
    exit; 
    */ 
} 

下載一個文件給我:利用響應::下載()從AWS S3

未處理異常

消息:

文件大小()[function.filesize]:Stat失敗爲https://s3.amazonaws.com/webapp/uploads/laravelsasuce.png

回答

0

解決方案:/laravel/response.php

你不能在aws文件上使用File :: size,因爲File :: size()=== filesize(),並且該函數無論出於何種原因都無法繪製S3文件。

enter image description here