Direct Download Not Working

Post your Click counter digestion problems here
Post Reply
prodbyola
Posts: 8
Joined: Thu Feb 21, 2019 11:05 pm

Direct Download Not Working

Post by prodbyola »

Thanks for this beautiful software. It solved my count problem except I'm now facing a new one. When I try to force direct download on my file using html code, the browser tries to download "Click.php." This happens for opera mini and some browsers won't just download. Please what can I do? Thanks for your help.
Klemen
Site Admin
Posts: 10114
Joined: Fri Feb 11, 2005 4:04 pm

Re: Direct Download Not Working

Post by Klemen »

I would have to see your setup in action to be sure, but you will most likely need to modify the code (headers PHP sends) to set the correct file name etc.

Or use the alternative HTML redirect and modify the code there (the bottom few lines) to force the download?
https://www.phpjunkyard.com/extras/ccou ... _click.zip
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
prodbyola
Posts: 8
Joined: Thu Feb 21, 2019 11:05 pm

Re: Direct Download Not Working

Post by prodbyola »

Hi,
Thank you for your kind help. I was trying to respond earlier but I couldn't post because I was receiving some error messages. In response to your reply, here's the code I'm using:

Code: Select all

<head><script src="mydomain/assets/counter/display.php"></script></head>
<body><div class="buttonHolder">
<form>
<a href="mydomain/assets/counter/click.php?id=1" download="file name" target="_blank"><input class="button" type="button" value="DOWNLOAD NOW" /></a>
</form>
<script>ccount_display('1')</script>
</div>
</body>
Also there's an "onclick" ref code that leads to the thank you page placed after the "file name" code.
But when someone hits the "Download Now" button, the browser tries to download click.php. Kindly help.
Klemen
Site Admin
Posts: 10114
Joined: Fri Feb 11, 2005 4:04 pm

Re: Direct Download Not Working

Post by Klemen »

prodbyola wrote: Fri Mar 01, 2019 1:37 amI was trying to respond earlier but I couldn't post because I was receiving some error messages.
That is probably mod_security detecting the post as a possible hacking attempt and blocking it.

I don't see anything wrong with the code you posted. You could try it without <form> tags and see if that helps.

If not, please share your exact page code (you can do it in a private message for privacy concerns).
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
prodbyola
Posts: 8
Joined: Thu Feb 21, 2019 11:05 pm

Re: Direct Download Not Working

Post by prodbyola »

Hi @Klemen,
Thanks for the assistance so far. I'm using wordpress and I'm just trying to insert the html code into a post. So I don't really know how to get the code for the whole page to you. But when I replaced the form tags with "div", I got the same result as above. Is there an alternate that may work? Thank you?
Klemen
Site Admin
Posts: 10114
Joined: Fri Feb 11, 2005 4:04 pm

Re: Direct Download Not Working

Post by Klemen »

Can you show the page (URL) where this is happening?
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
prodbyola
Posts: 8
Joined: Thu Feb 21, 2019 11:05 pm

Re: Direct Download Not Working

Post by prodbyola »

Thanks @Klemen
The here's a sample page I'm working on https://lix.tdmstudios.com.ng/psalm27-imhudia/. The "Download Now" button tries to download "Click.php" in Opera Mini and doesn't work properly in other browsers.
Klemen
Site Admin
Posts: 10114
Joined: Fri Feb 11, 2005 4:04 pm

Re: Direct Download Not Working

Post by Klemen »

Two problems I see:

1. Your link ID 1 is not a valid MP3 file, but redirects to the page itself:

Code: Select all

https://lix.tdmstudios.com.ng/assets/counter/click.php?id=1
The ID 1 link in Ccount admin panel should be set to the MP3 file:

Code: Select all

https://lix.tdmstudios.com.ng/wp-content/uploads/2019/01/imhudia_psalm37.mp3
2. Remove this code from the link:

Code: Select all

onclick="location.href='https://lix.tdmstudios.com.ng/thank-you/';"
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
prodbyola
Posts: 8
Joined: Thu Feb 21, 2019 11:05 pm

Re: Direct Download Not Working

Post by prodbyola »

Oh! That was a mistake which I just corrected now. Initially I actually set the file link https://lix.tdmstudios.com.ng/wp-conten ... salm37.mp3 in CCount admin and I was getting the same result. Now I've followed both instructions you just gave me but unfortunately... I'm still getting the same result :?
Klemen
Site Admin
Posts: 10114
Joined: Fri Feb 11, 2005 4:04 pm

Re: Direct Download Not Working

Post by Klemen »

How about if you add something like this in click.php just below line starting with setcookie?

Code: Select all

$url = parse_url(str_replace('&amp;', '&', $ccount_database[$id]['L']));
$path = isset($url['path']) ? pathinfo($url['path']) : array();

if (isset($path['extension']) && strtolower($path['extension']) == 'mp3')
{
    $file['path'] = '../..' . $url['path'];
    $file['name'] = $path['basename'];

    // Send the file as an attachment to prevent malicious code from executing
    header("Pragma: "); # To fix a bug in IE when running https
    header("Cache-Control: "); # To fix a bug in IE when running https
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename=' . $file['name']);
    readfile($file['path']);
    die();
}
I didn't test it so if you get an error (or 0 file size), try adding one more "../" to the $file['path'] line.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
prodbyola
Posts: 8
Joined: Thu Feb 21, 2019 11:05 pm

Re: Direct Download Not Working

Post by prodbyola »

Hi Klemen,
Thanks for your help so far. After trying your instructions above, the browser now tries to get a "click.htm" file. :(
Klemen
Site Admin
Posts: 10114
Joined: Fri Feb 11, 2005 4:04 pm

Re: Direct Download Not Working

Post by Klemen »

Works fine for me in Firefox and Chrome.

Doesn't work in IE (nothing happens when I click the link, try removing <form> tags around it).

Don't have Opera to test. Try clearing your cache.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
prodbyola
Posts: 8
Joined: Thu Feb 21, 2019 11:05 pm

Re: Direct Download Not Working

Post by prodbyola »

Thank you Klemen,
It's already working in Chrome. It's not working on Opera Mini. I tried with a smartphone and tablet. On the smartphone, it tries to download "click-1.php" and the "-1" increases the more I try to download. On the tablet, it tries to download "click.htm." I don't care much about IE as most of my web visitors are likely to be mobile users using Chrome or Opera. So I really wish it could work on opera.
Klemen
Site Admin
Posts: 10114
Joined: Fri Feb 11, 2005 4:04 pm

Re: Direct Download Not Working

Post by Klemen »

I am out of ideas, unfortunately. I recommend hiring a PHP developer to login to your server, have a look and try to fix this for you.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
prodbyola
Posts: 8
Joined: Thu Feb 21, 2019 11:05 pm

Re: Direct Download Not Working

Post by prodbyola »

Thank you sooooo much. You've been a great help.
Post Reply