Jump to content

force download crashes browser - help


richrock

Recommended Posts

Hi,

 

I've been trying to get a script to force a download of a zip archive, but it's not working... I am too dumb to figure why, although I've tried a lot of options.

 

    // Create a zip file based on parameters.
    // Set up the POST data
    $z_title    = $_POST['album'];
    $z_id       = $_POST['id'];

    require_once('../../../configuration.php');
    $jconfig = new JConfig();

    $db_error = "Database not found. Please contact a system administrator.";

    $db_config = mysql_connect( $jconfig->host, $jconfig->user, $jconfig->password ) or die( $db_error );
    mysql_select_db( $jconfig->db, $db_config ) or die( $db_error );

    $q = "SELECT zip_file FROM jos_music_albums WHERE id = '" . $z_id . "'";
    $query_execute = mysql_query($q);
    $result = mysql_fetch_row($query_execute);
    $destination = $result[0];
    mysql_close($db_config);

    $destination_alpha = basename($destination);
    $destination_bravo = $_SERVER['DOCUMENT_ROOT']. "/bromptons_auctioneers_15/" . $destination;

    $filesize = filesize($destination);

    header("Pragma: public"); // required
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false); // required for certain browsers
    header("Content-Type: application/zip");

    header("Content-Disposition: attachment; filename=\"".basename($destination)."\";" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".$filesize);
    readfile("$destination");
    exit;

 

The actual test file is a zip archive located in http://www.sitename.com/music/artist/album.zip

 

It's *definitely* there  ::)

 

I have tried using absolute paths either from the url or from the fileserver, and relative paths don't seem to work either.  The error I get (this was with the code above):

 

Warning: filesize() [function.filesize]: stat failed for music/Sibelius/Sibelius/Sibelius.zip in F:\html\bromptons_auctioneers_15\components\com_music\assets\zipit.php  on line 25

 

Warning: readfile(music/Sibelius/Sibelius/Sibelius.zip) [function.readfile]: failed to open stream: No such file or directory in F:\html\bromptons_auctioneers_15\components\com_music\assets\zipit.php on line 36

 

When I have managed to get this to work (supposedly), I crash the browser.  The memory usage leaps up - first time I noticed my  browser was using 1.8gb of memory, increasing by about +/- 250mb a second.  This seems to occur everytime I use absolute paths, and cannot figure why. Firebug reports nothing wrong (maybe it's failed by this point), and am at a loss.

 

Any ideas/alternative code would be appreciated - codes a bit of a mess too, there's remants of stuff I've tried before too...

Link to comment
https://forums.phpfreaks.com/topic/205166-force-download-crashes-browser-help/
Share on other sites

Right it's now working, although I have another problem affecting the downloads - filesize($filename) fails.  The error I get is:

 

Warning: filesize() [function.filesize]: stat failed for /bromptons_auctioneers_15/music/Sibelius/Sibelius/01 Violin Concerto.mp3 in F:\html\bromptons_auctioneers_15\components\com_music\assets\zipit.php  on line 35

 

And I have tried using clearstatcache() at the start of the script to reset anything.  Still with the errors...

 

FWIW - the typical filesizes are around the 15-20mb mark...

Right, figured the filesize refers to actual location (as mentioned earlier), so I now get a report of

 

34064439

 

when I get the filesize of a 15mb mp3.  That may explain why I'm only getting 400-1000k download file sizes.  Can anyone help with filesize()?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.