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
https://forums.phpfreaks.com/topic/34457-force-download-help/
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
https://forums.phpfreaks.com/topic/34457-force-download-help/#findComment-162257
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
https://forums.phpfreaks.com/topic/34457-force-download-help/#findComment-162264
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
https://forums.phpfreaks.com/topic/34457-force-download-help/#findComment-162294
Share on other sites

echos the file name correctly and links to the file correctly but when you try to download it, it wont download the whole file.  only downloads ~400kb and the file could be a few meg.  the files it links to are in sub directories of where download.php reside and where the html page is.
Link to comment
https://forums.phpfreaks.com/topic/34457-force-download-help/#findComment-162312
Share on other sites

basically, your script isn't finding the files that are tucked into the subdirectories. it's probably due to the <a> tag that's sending you to download.php -- without seeing what it looks like in HTML (not the PHP side), there's no way to know why it's not working.
Link to comment
https://forums.phpfreaks.com/topic/34457-force-download-help/#findComment-162352
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
https://forums.phpfreaks.com/topic/34457-force-download-help/#findComment-162367
Share on other sites

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.