【发布时间】:2017-03-30 09:21:49
【问题描述】:
我面临一个问题,我想在下载图像后保存数据。我的图像已成功下载,之后我想维护下载历史。这是我的功能:-
enter code here
public function UserImageDownlaod($userid=null,$imageid=null){
$imagedata = DB::table('alt_images')->where('id',$imageid)->first();
$imagedata = json_decode(json_encode($imagedata),true);
$destination = 'images/ContributorImages'.'/';
$pathToFile = $destination.$imagedata['img'];
return response()->download($pathToFile);
//Now i want to save the history of downloaded images
$history= new DownloadHistory;
$history->user_id = Auth::user()->id;
$history->alt_image_id = $imageid;
$history->save();
}
现在您可以在 return response()->download($pathToFile) 行之后看到我想保存历史数据。我希望当用户单击“确定”按钮时,数据将保存在历史记录表中。谁能帮我。
【问题讨论】:
-
这是默认的浏览器弹出窗口。我们无法在代码中获取它的事件。
-
如果我在响应下载之前保存它会保存但如果用户点击取消按钮。那么数据将被保存它会给我们带来问题
-
你不能把return语句放在函数的末尾
-
如果我输入结束,我知道我的数据将被保存,但如果用户点击取消,它也会将数据保存在历史表中
-
你为什么不做类似的事情 - 当用户点击任何下载按钮时,会通过 javascript 生成一个弹出窗口,其中包含“你确定要下载图像”之类的消息。然后你会在弹出窗口中同时看到 OK 和 CANCEL 按钮。然后,如果用户单击“确定”,则将其视为您的用户想要下载图像,否则不要执行下载图像代码。
标签: php jquery laravel-5.2