mike760534211 Posted January 16, 2007 Share Posted January 16, 2007 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 3mbhow can i correct the download.php to read the file correctly and force download the correct file size Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 16, 2007 Share Posted January 16, 2007 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] Quote Link to comment Share on other sites More sharing options...
mike760534211 Posted January 16, 2007 Author Share Posted January 16, 2007 <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);?> Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 16, 2007 Share Posted January 16, 2007 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. Quote Link to comment Share on other sites More sharing options...
mike760534211 Posted January 16, 2007 Author Share Posted January 16, 2007 echo "<a HREF=download.php?file=$file>$count_hits. $file </a><br>" is the href from the refering page and the $path has been removed with the same results. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 16, 2007 Share Posted January 16, 2007 what does that link look like on the HTML side? Quote Link to comment Share on other sites More sharing options...
mike760534211 Posted January 16, 2007 Author Share Posted January 16, 2007 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. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 16, 2007 Share Posted January 16, 2007 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. Quote Link to comment Share on other sites More sharing options...
mike760534211 Posted January 16, 2007 Author Share Posted January 16, 2007 ok i am not sure which code you are asking for. are you looking for the code where the link is echoed back on the website or the source code from the page that the href is in Quote Link to comment Share on other sites More sharing options...
mike760534211 Posted January 16, 2007 Author Share Posted January 16, 2007 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)); Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 16, 2007 Share Posted January 16, 2007 you posed the error message earlier. What remains a mystery is what the refering page's <a> link looks like. Quote Link to comment Share on other sites More sharing options...
mike760534211 Posted January 16, 2007 Author Share Posted January 16, 2007 <a HREF=download.php?file=$file>$count_hits. $file </a>and it generates the links to the files correctly on the page Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 16, 2007 Share Posted January 16, 2007 Well, without knowing what the variables $file or $count_hits, I can't recreate the link. It'd be nice to see a finished link, though. Right out of the HTML source from your browser. Quote Link to comment Share on other sites More sharing options...
mike760534211 Posted January 16, 2007 Author Share Posted January 16, 2007 $ count_hits returns a valus of how many times it found the search string.$file does nothing more than echo the file name that matched the search string. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.