Search code examples
phpjquerydownloadfancyboxhref

Download function for fancyBox


$(".fancybox").fancybox({
                        afterLoad: function() {
                            this.title = '<a href=downlaod.php?img="'+ this.href + '"><img src="download.png" alt="" align="right"/></a> ' + this.title;
                        },
                        helpers : {
                            title: {
                                type: 'outside'
                            }
                        }
                    });

As you can see I'm using fancyBox and I'm looking for an option for downloading the current image of the gallery you're viewing (not as ZIP). Everything works so far fine, but the URL to the download is not

www.website.com/download.php?img=image.jpg

instead it's

 www.website.com/download.php?img="image.jpg"

That's an error (redirects to the 404 page). I am doing something wrong but I just can't figure it out.

The images are linked this way:

<a class="fancybox" href="image.jpg" rel="gallery" title="image"><img src="thumbnail.jpg" alt="" /></a>
<a class="fancybox" href="image2.jpg" rel="gallery" title="image2"><img src="thumbnail2.jpg" alt="" /></a>

My only guess is that the script is reading the href="image.jpg" as a string instead as a varibale.

Link to the download.php


Solution

  • You misplaced the ":

    $(".fancybox").fancybox({
                            afterLoad: function() {
                                this.title = '<a href="download.php?img='+ this.href + '"><img src="download.png" alt="" align="right"/></a> ' + this.title;
                            },
                            helpers : {
                                title: {
                                    type: 'outside'
                                }
                            }
                        });