SitePoint Sponsor |
|
User Tag List
Results 1 to 14 of 14
Thread: Download counter
-
Sep 6, 2000, 15:14 #1
- Join Date
- Jul 2000
- Location
- Nowhere
- Posts
- 278
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Not just increasing the value of a table cell. It's one step further:
The download counter should only spin if the link has really been clicked or the download has started. At the moment I'm having a redirect to another download.php3 page which counts the counter up by one.
Another problem is that the download doesn't start. How do I automatically let a download begin when redirected to this page?
TIA!
-
Sep 6, 2000, 17:41 #2
- Join Date
- Apr 2000
- Location
- Melbourne, Australia
- Posts
- 2,571
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Making a download begin is as simple as including a META refresh tag in the HEAD of the confirmation screen (generated by your counter increment script):
Code:<META HTTP-EQUIV=refresh CONTENT="0;URL=thefile.zip">
Kevin Yank
CTO, sitepoint.com
I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
Baby’s got back—a hard back, that is: The Ultimate CSS Reference
-
Sep 6, 2000, 18:13 #3
You might want to look at the script here
http://www136.l4.xodox.com/index2.html
hope this helps!
-
Sep 7, 2000, 03:29 #4
- Join Date
- Jul 2000
- Location
- Nowhere
- Posts
- 278
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally posted by kyank
As for only incrementing the counter if the download actually happens, the solution there is to make the counter script actually send the requested file to the browser. Use a call to header() to tell the browser what MIME type to receive, then use readfile() to send the contents of the file to the browser.
Sorry for this dump ques, but..... how can I do this? If possible can you provide me with some code?
Thanks alot!
-
Sep 7, 2000, 04:08 #5
- Join Date
- Apr 2000
- Location
- Melbourne, Australia
- Posts
- 2,571
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
For example, to send "myimage.gif":
Code:Header("Content-Type: image/gif"); readfile("myimage.gif");
Kevin Yank
CTO, sitepoint.com
I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
Baby’s got back—a hard back, that is: The Ultimate CSS Reference
-
Sep 7, 2000, 05:45 #6
- Join Date
- Jul 2000
- Location
- Nowhere
- Posts
- 278
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Cool! it works!
How can I customize the name of this file? In my download manager it always displays the name of my php3 file.
And the same with file size. It's always unknown over ftp...
[Edited by DIMA on 09-07-2000 at 07:05 AM]
-
Sep 7, 2000, 09:42 #7
- Join Date
- Apr 2000
- Location
- Melbourne, Australia
- Posts
- 2,571
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
The file size can be set with an HTTP header (I'll have to look it up when I get home if nobody else comes up with it before then). I've heard the file name can be too, but I've never had opportunity to try. I'll try to find an appropriate header for that, too.
Kevin Yank
CTO, sitepoint.com
I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
Baby’s got back—a hard back, that is: The Ultimate CSS Reference
-
Sep 7, 2000, 10:24 #8
- Join Date
- Jul 2000
- Location
- Nowhere
- Posts
- 278
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks! I'll wait...
-
Sep 7, 2000, 11:56 #9
- Join Date
- Jul 2000
- Location
- Warwickshire, England
- Posts
- 557
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Content-Type: application/zip
Content-Disposition: attachment; filename=filename.zip
Content-length: nbytes
-
Sep 7, 2000, 12:21 #10
- Join Date
- Jul 2000
- Location
- Nowhere
- Posts
- 278
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hey thanks!
the name works correctly now.... but the file size is still unknown
Code:header("Content-length: nbytes");
Can't I automate this process?
TIA
-
Sep 7, 2000, 12:51 #11
- Join Date
- Jul 2000
- Location
- Warwickshire, England
- Posts
- 557
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
you can use the filesize (filename) which returns a file size (integer) in bytes...
$fsize = filesize("foo.zip");
-
Sep 7, 2000, 13:16 #12
- Join Date
- Jul 2000
- Location
- Nowhere
- Posts
- 278
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I did this and it's still unknown... the only thing which is different from yours is that it's not a filename but a whole URL.
Code:$url = $row["url"]; $size = filesize($url); header("Content-Type: application/x-stuffit"); header("Content-Disposition: attachment; filename=$title $version"); header("Content-Length: $size");
-
Sep 7, 2000, 16:06 #13
- Join Date
- Jul 2000
- Location
- Warwickshire, England
- Posts
- 557
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No, it has to a filename usually including a path or in the same directory...
-
Sep 8, 2000, 09:50 #14
- Join Date
- Apr 2000
- Location
- Melbourne, Australia
- Posts
- 2,571
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
You definitely don't want to use a URL for your filename -- this slows things down tremendously, as PHP retrieves the file using an HTTP download (masquerading as a browser requesting the file from your Web server) rather than just opening it directly from your hard drive.
Kevin Yank
CTO, sitepoint.com
I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
Baby’s got back—a hard back, that is: The Ultimate CSS Reference
Bookmarks