0
I am trying to make a script for Download Images, by Ajax. It can be one or several. As you can see in JS, it has a function each
searching for the selected images in the system.
Then, I call Ajax to take as parameter the ID of the Photo for me to do a database search, search the address of the photo and download.
The code returns the encoded image instead of downloading. What do I need to change ? It is necessary to use AJAX ?
// Download de Imagens
$("#download").click(function(){
var ids = '';
$("input[name='foto[]']:checked").each(function(){
ids = $(this).val() + ',' + ids;
});
ids = ids.substr(0,ids.length-1);
$.ajax({
url: urlBase + '/portfolio/download/',
cache: false,
type: "POST",
responseType: 'blob',
data: {ids:ids}
});
});
# Download de Imagens
public function anyDownload(){
$ids = Input::get('ids');
$imagem = GaleriaProjeto::find($ids);
$headers = array(
'Content-Type: image/jpg',
);
return Response::download(URL::to('/img/portfolio/'.$imagem->imagem, $imagem->imagem, $headers));
}
Use stacksnippet only to play problems with css, html and js that can be run.
– Guilherme Nascimento