8 Replies - 591 Views - Last Post: 24 January 2012 - 09:14 PM

#1 L27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 11-January 12

no download information.

Posted 24 January 2012 - 07:00 PM

I want to setup a downloads section in my website but i'm unsure of how to get it to display information. If i were to direct my browser to the file now i get the "unknown time remaining" thing how can i get it to display the right information.
Is This A Good Question/Topic? 0
  • +

Replies To: no download information.

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1291
  • View blog
  • Posts: 7,599
  • Joined: 07-September 06

Re: no download information.

Posted 24 January 2012 - 08:00 PM

If you are talking about the download dialog box that the browser has, then there really isn't anything you can do to make that a better estimate. What you could attempt to do is make sure you send the file size headers back to the client when the file is requested. That should allow the browser to understand that it is about to get x bytes of data, and then it can use the rate at which it is receiving information to determine how much longer it should take until the file is fully downloaded.
Was This Post Helpful? 0
  • +
  • -

#3 L27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 11-January 12

Re: no download information.

Posted 24 January 2012 - 08:28 PM

View PostBetaWar, on 24 January 2012 - 08:00 PM, said:

If you are talking about the download dialog box that the browser has, then there really isn't anything you can do to make that a better estimate. What you could attempt to do is make sure you send the file size headers back to the client when the file is requested. That should allow the browser to understand that it is about to get x bytes of data, and then it can use the rate at which it is receiving information to determine how much longer it should take until the file is fully downloaded.

Yeah how would I go about making sure to send the file size to the client.
This is what I get when i start the download.
Posted Image

Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1291
  • View blog
  • Posts: 7,599
  • Joined: 07-September 06

Re: no download information.

Posted 24 January 2012 - 08:34 PM

You want to send the Content-Length header. This will require a bit of server-side coding, or the ability to modify your server (though I don't know where the setting would be at, unless it is in the configuration file).

If you are using PHP then take a look at http://us.php.net/ma...tion.header.php for information about how to send headers.
Was This Post Helpful? 0
  • +
  • -

#5 L27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 11-January 12

Re: no download information.

Posted 24 January 2012 - 08:44 PM

View PostBetaWar, on 24 January 2012 - 08:34 PM, said:

You want to send the Content-Length header. This will require a bit of server-side coding, or the ability to modify your server (though I don't know where the setting would be at, unless it is in the configuration file).

If you are using PHP then take a look at http://us.php.net/ma...tion.header.php for information about how to send headers.

So something like this?

<?php
// We'll be outputting a ZIP
header('Content-type: application/zip');

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="blahblah.zip"');

// File size =
header('Content-Length: 63213');
?>



And then save it as blahblah.php then put it in the download directory?
Or am I very wrong here.

Thanks.
Was This Post Helpful? 0
  • +
  • -

#6 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1291
  • View blog
  • Posts: 7,599
  • Joined: 07-September 06

Re: no download information.

Posted 24 January 2012 - 08:56 PM

I would add a few more headers in there, for caching and stuff like that (example:):

$file = 'blahblah.zip'; // file to download
header("Expires: 0"); // when the download expires (never)
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // when it was last modified (not really needed, but the user may want to know before they download a new copy of the same file)
header("Cache-Control: no-store, no-cache, must-revalidate"); // don't allow caching
header("Cache-Control: post-check=0, pre-check=0", false); // add a few more no cache headers
header("Pragma: no-cache"); // make it even more apparent
header("Content-type: application/zip"); // the mime type of the file (this will be something you should modify depending on the file)
header('Content-length: '.filesize($file)); // file size
header('Content-disposition: attachment; filename='.basename($file)); // filename
readfile($file); // output the file to the browser


Was This Post Helpful? 0
  • +
  • -

#7 L27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 11-January 12

Re: no download information.

Posted 24 January 2012 - 09:03 PM

View PostBetaWar, on 24 January 2012 - 08:56 PM, said:

I would add a few more headers in there, for caching and stuff like that (example:):

$file = 'blahblah.zip'; // file to download
header("Expires: 0"); // when the download expires (never)
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // when it was last modified (not really needed, but the user may want to know before they download a new copy of the same file)
header("Cache-Control: no-store, no-cache, must-revalidate"); // don't allow caching
header("Cache-Control: post-check=0, pre-check=0", false); // add a few more no cache headers
header("Pragma: no-cache"); // make it even more apparent
header("Content-type: application/zip"); // the mime type of the file (this will be something you should modify depending on the file)
header('Content-length: '.filesize($file)); // file size
header('Content-disposition: attachment; filename='.basename($file)); // filename
readfile($file); // output the file to the browser


Ok thanks and then what do I name it and where do I place it on my site?
I'm guessing
Name = Anything.
Place on site = same directory as the download files.
Correct?
Was This Post Helpful? 0
  • +
  • -

#8 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1291
  • View blog
  • Posts: 7,599
  • Joined: 07-September 06

Re: no download information.

Posted 24 January 2012 - 09:07 PM

Well, basically all you need to do is place the path (relative, or absolute) and filename in the $file variable.

For example:
$file = "path/to/file/blahblah.zip";


Then you can use mime_content_type to get the mime type of a file:
http://us3.php.net/m...ontent-type.php
Was This Post Helpful? 0
  • +
  • -

#9 L27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 11-January 12

Re: no download information.

Posted 24 January 2012 - 09:14 PM

View PostBetaWar, on 24 January 2012 - 09:07 PM, said:

Well, basically all you need to do is place the path (relative, or absolute) and filename in the $file variable.

For example:
$file = "path/to/file/blahblah.zip";


Then you can use mime_content_type to get the mime type of a file:
http://us3.php.net/m...ontent-type.php

How far does the path have to go back like /home/user/public_html/download/file/ ?
Also you'll have to dumb down the mime thing for me, an example maybe? I don't use php much.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1