This commit is contained in:
jitendra 2019-10-11 11:46:19 +05:30
parent e829a8c1a9
commit a3bb10a8b6
1 changed files with 27 additions and 23 deletions

View File

@ -117,34 +117,38 @@ class ProductController extends Controller
*/
public function downloadSample()
{
if (request('type') == 'link') {
$productDownloadableLink = $this->productDownloadableLinkRepository->findOrFail(request('id'));
try {
if (request('type') == 'link') {
$productDownloadableLink = $this->productDownloadableLinkRepository->findOrFail(request('id'));
if ($productDownloadableLink->sample_type == 'file')
return Storage::download($productDownloadableLink->sample_file);
else {
$fileName = $name = substr($productDownloadableLink->sample_url, strrpos($productDownloadableLink->sample_url, '/') + 1);
if ($productDownloadableLink->sample_type == 'file')
return Storage::download($productDownloadableLink->sample_file);
else {
$fileName = $name = substr($productDownloadableLink->sample_url, strrpos($productDownloadableLink->sample_url, '/') + 1);
$tempImage = tempnam(sys_get_temp_dir(), $fileName);
$tempImage = tempnam(sys_get_temp_dir(), $fileName);
copy($productDownloadableLink->sample_url, $tempImage);
copy($productDownloadableLink->sample_url, $tempImage);
return response()->download($tempImage, $fileName);
}
} else {
$productDownloadableSample = $this->productDownloadableSampleRepository->findOrFail(request('id'));
if ($productDownloadableSample->type == 'file')
return Storage::download($productDownloadableSample->file);
else {
$fileName = $name = substr($productDownloadableSample->url, strrpos($productDownloadableSample->url, '/') + 1);
$tempImage = tempnam(sys_get_temp_dir(), $fileName);
copy($productDownloadableSample->url, $tempImage);
return response()->download($tempImage, $fileName);
return response()->download($tempImage, $fileName);
}
} else {
$productDownloadableSample = $this->productDownloadableSampleRepository->findOrFail(request('id'));
if ($productDownloadableSample->type == 'file')
return Storage::download($productDownloadableSample->file);
else {
$fileName = $name = substr($productDownloadableSample->url, strrpos($productDownloadableSample->url, '/') + 1);
$tempImage = tempnam(sys_get_temp_dir(), $fileName);
copy($productDownloadableSample->url, $tempImage);
return response()->download($tempImage, $fileName);
}
}
} catch(\Exception $e) {
abort(404);
}
}
}