2017-06-13 7 views
1

Download-Link zeigt: -Datei herunterladen von URL ohne den vollständigen Pfad in Laravel

<a href='"+ downloadlink + '/attachment-download/' + $('#employee_ID').val()+'/'+ res[i].file_name +"'>  

Route: -

Route::get('/attachment-download/{id}/{filename}', array(
'uses' => '[email protected]' 
)); 

Befestigung Controller: -

public function getDownloadAttachments($id,$filename){ 
    $file="./img/user-icon.png"; 

    $resource = \Employee::WhereCompany()->findOrfail($id); 

    $path = $this->attachmentsList($resource); 

    foreach($path as $index => $attachment){ 
     if ($filename == $attachment['file_name']) { 
     $filePath = $attachment['url']; 
     } 
    } 
    //return \Response::download($file); 
    return \Response::download($filePath); 
} 


File URL Output:- 
https://zetpayroll.s3.ap-south-1.amazonaws.com/employees/81/Screenshot%20from%202017-04-26%2015%3A07%3A45.png?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAI57OFN3HPCBPQZIQ%2F20170612%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Date=20170612T144818Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Signature=59ecc4d11b7ed71bd336531bd7f4ab7c84da6b7424878d6487679c97a8c52ca7 

In diesem Wenn versuchen Datei mit statischem Pfad wie

herunterladen

ist es gut heruntergeladen. Aber nicht möglich, Datei von AWS URL herunterzuladen, bitte helfen Sie mir, Datei automatisch mit URL herunter zu laden. Oder Wie man den Pfad von der URL in Laravel oder PHP bekommt. Danke.

+0

Sind Sie sicher, dass Ihre AWS-URL korrekt ist? – hassan

+0

Ja. Während dieser Pfad in der Browser-Datei heruntergeladen wird. Aber ich habe den Pfad in Frage "/zetpayroll.s3.ap-south-1" geändert – Raju

Antwort

0
Using this above function All files are downloaded. 
But while try to open those files are opened (.text, .csv, .pdf..). 
But not open images. 

$fileContent = file_get_contents($filePath); 

$response = response($fileContent, 200, [ 
    'Content-Type' => 'application/json', 
    'Content-Disposition' => 'attachment; filename="'.$filename.'"', 
]); 

return $response; 
Verwandte Themen