Jump to content

force download help


mike760534211

Recommended Posts

i am using the download.php code snippet posted here.  when i use that to download a file that is in a sub directory of where the download.php file is it will not force download the file correctly.  it usually makes the downloaded file ~400kb when the file may be over 3mb

how can i correct the download.php to read the file correctly and force download the correct file size
Link to comment
Share on other sites

You're probably getting a PHP parse error in your code someplace, but the force-download part is making it download the error instead of display it. Open the downloaded file in a text editor and you'll probably see the cause.

best blind guess to fix it:
[code]<?php
$file = realpath(".").$_REQUEST['file'];
?>
[/code]
Link to comment
Share on other sites

<br />
<b>Warning</b>:  filesize() [<a href='function.filesize'>function.filesize</a>]: stat failed for / 'flie name here' in <b>%web_root%download.php</b> on line <b>14</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at %web_root%\download.php:14) in <b>%web_root%\download.php</b> on line <b>14</b><br />


script using
<?php

$file = realpath(".").$_REQUEST['file'];;

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=1, pre-check=1");

header("Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=".basename($path."/".$file));

header( "Content-Description: File Transfer");
header('Accept-Ranges: bytes');
header('Content-Length: ' . filesize($path."/".$file));
@readfile($path."/".$file);

?>
Link to comment
Share on other sites

first thing:
[quote]Warning:  filesize() [<a href='function.filesize'>function.filesize[/url]]: stat failed for / 'flie name here' in %web_root%download.php on line 14[/quote]
are you passing it an <a> tag ("<a href...>") or a filename? I'd be curious to see the <a> tag from the refering page.

Also, the basename($path."/".$file) might be giving you trouble (since you haven't set $path to anything). You should be able to return the script to normal by removing the '$path."/".' part.
Link to comment
Share on other sites

when i download a file and open it with notepad the file contains:
<br />
<b>Warning</b>:  filesize() [<a href='function.filesize'>function.filesize</a>]: stat failed for E:\web_svr\MP3\mp3mp3_Beyonce_09_Irreplaceable.mp3 in <b>E:\web_svr\MP3\mp3\download.php</b> on line <b>14</b><br />
<br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at E:\web_svr\MP3\mp3\download.php:14) in <b>E:\web_svr\MP3\mp3\download.php</b> on line <b>14</b><br />

line 14 of download.php is:
header('Content-Length: ' . filesize($file));
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.