dafallenangel Posted December 13, 2008 Share Posted December 13, 2008 I downloaded a PHP Downloader script with Counter and I tested it out how they had it setup and for some reason the first page works find but the second page just shows up blank.. first page is grabbing the filename and count out of mysql and then echos the filename into a url download.php?filename=$filename now my register_globals is set to off but that shouldn't effect any since my forum i wrote is sending veribles through url as well. here is the second page download.php $download_path = 'download/'; /* set up mysql connection */ include("inc.mysql.php"); if (!empty($file)) { /* query database */ $result = mysql_query('SELECT filename FROM download'); /* check each row for filename and send file via http header */ while ($row = mysql_fetch_assoc($result)) { if ($row["filename"] == $file) { $result = mysql_query("UPDATE download SET downloads=downloads+1 WHERE filename='" . $file . "'"); header('Location: ' . $download_path . basename($file)); } } } Thank you DaFallenAngel Quote Link to comment Share on other sites More sharing options...
chronister Posted December 13, 2008 Share Posted December 13, 2008 Add this to the top of the page ini_set('error_reporting', E_ALL); It should show you the errors and give you a good idea of whats wrong. I don't see anything that should echo on screen. The second page is only a "force download" page. I take it that the download is not being forced? Nate Quote Link to comment Share on other sites More sharing options...
dafallenangel Posted December 13, 2008 Author Share Posted December 13, 2008 still a blank page ??? and it should enforce a download.. I know this script works because a old friend had it working (no longer in contact with him). Quote Link to comment Share on other sites More sharing options...
chronister Posted December 13, 2008 Share Posted December 13, 2008 When I modify it a little and run it, it redirects to the file specified in the header(), it does not force the download because it does not have the proper headers and such. Here is some code I have that DOES force a download. I even tested it in place of yours and it forced the download properly. I integrated it with your code, try that and see what you get. (there might be errors as I did this real quickly and cannot truly test it because I don't have the database information to test against.) <?php $download_path = 'download/'; /* set up mysql connection */ include("inc.mysql.php"); if (!empty($file)) { /* query database */ $result = mysql_query('SELECT filename FROM download'); /* check each row for filename and send file via http header */ while ($row = mysql_fetch_assoc($result)) { if ($row["filename"] == $file) { $result = mysql_query("UPDATE download SET downloads=downloads+1 WHERE filename='" . $file . "'"); $filename = $download_path.$file // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); // addition by Jorg Weske $file_extension = strtolower(substr(strrchr($filename,"."),1)); switch( $file_extension ) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } 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: $ctype"); // change, added quotes to allow spaces in filenames, by Rajkumar Singh header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); } } } ?> Quote Link to comment Share on other sites More sharing options...
dafallenangel Posted December 14, 2008 Author Share Posted December 14, 2008 Well i figured out what the problem was i need to have register_globals set to on.. but question is there a way to edit this script so i don't need register_globals to be set to on? Quote Link to comment Share on other sites More sharing options...
chronister Posted December 14, 2008 Share Posted December 14, 2008 register_globals should not make a difference. I have them turned off and it works for me.... try this... make a file called notes.txt and put something in it... it don't matter what it is, it just needs to have data so you know that it worked.... Then run this code <?php $download_path = '/'; $filename = 'notes.txt'; // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); // addition by Jorg Weske $file_extension = strtolower(substr(strrchr($filename,"."),1)); switch( $file_extension ) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } 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: $ctype"); // change, added quotes to allow spaces in filenames, by Rajkumar Singh header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); ?> It works with register_globals off with my server.... register globals *should* not have any effect on what this script does though I could be wrong. Nate Quote Link to comment Share on other sites More sharing options...
dafallenangel Posted December 14, 2008 Author Share Posted December 14, 2008 register_globals should not make a difference. I have them turned off and it works for me.... try this... make a file called notes.txt and put something in it... it don't matter what it is, it just needs to have data so you know that it worked.... Then run this code <?php $download_path = '/'; $filename = 'notes.txt'; // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); // addition by Jorg Weske $file_extension = strtolower(substr(strrchr($filename,"."),1)); switch( $file_extension ) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } 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: $ctype"); // change, added quotes to allow spaces in filenames, by Rajkumar Singh header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); ?> It works with register_globals off with my server.... register globals *should* not have any effect on what this script does though I could be wrong. Nate i wasn't meaning that code i ment the code that i had it wasn't working because i had register_globals set to off and when i tried your code i got errors at if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); Quote Link to comment Share on other sites More sharing options...
chronister Posted December 14, 2008 Share Posted December 14, 2008 hmmmmm.... when I run this.... <?php $download_path = '/'; $filename = 'notes.txt'; // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); // addition by Jorg Weske $file_extension = strtolower(substr(strrchr($filename,"."),1)); switch( $file_extension ) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } 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: $ctype"); // change, added quotes to allow spaces in filenames, by Rajkumar Singh header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); ?> it works perfectly with no errors.... what errors are you getting? Nate Quote Link to comment Share on other sites More sharing options...
dafallenangel Posted December 14, 2008 Author Share Posted December 14, 2008 see that script works fine for me but i mean the one you posted at a few posts ago i am getting Parse error: syntax error, unexpected T_IF in C:\xampp\htdocs\download.php on line 20 which is line if(ini_get('zlib.output_compression')) now my database consist of id, title, filename, downloads Quote Link to comment Share on other sites More sharing options...
chronister Posted December 14, 2008 Share Posted December 14, 2008 In the first chunk of code I posted that integrated yours and mine.... $filename = $download_path.$file <-- is missing a ; oops Quote Link to comment Share on other sites More sharing options...
dafallenangel Posted December 14, 2008 Author Share Posted December 14, 2008 In the first chunk of code I posted that integrated yours and mine.... $filename = $download_path.$file <-- is missing a ; oops thats already in there thats line 17 Quote Link to comment Share on other sites More sharing options...
chronister Posted December 14, 2008 Share Posted December 14, 2008 If your still getting errors, post the code you have so I can look at it. Nate Quote Link to comment Share on other sites More sharing options...
dafallenangel Posted December 14, 2008 Author Share Posted December 14, 2008 <?php $download_path = 'download/'; /* set up mysql connection */ include("inc.mysql.php"); if (!empty($file)) { /* query database */ $result = mysql_query('SELECT filename FROM download'); /* check each row for filename and send file via http header */ while ($row = mysql_fetch_assoc($result)) { if ($row["filename"] == $file) { $result = mysql_query("UPDATE download SET downloads=downloads+1 WHERE filename='" . $file . "'"); $filename = $download_path.$file // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); // addition by Jorg Weske $file_extension = strtolower(substr(strrchr($filename,"."),1)); switch( $file_extension ) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } 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: $ctype"); // change, added quotes to allow spaces in filenames, by Rajkumar Singh header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); } } } ?> Quote Link to comment Share on other sites More sharing options...
chronister Posted December 14, 2008 Share Posted December 14, 2008 $filename = $download_path.$file add a ; to the end of this line.... thats why your getting an error. It is missing a semi-colon. Nate Quote Link to comment Share on other sites More sharing options...
dafallenangel Posted December 14, 2008 Author Share Posted December 14, 2008 $filename = $download_path.$file add a ; to the end of this line.... thats why your getting an error. It is missing a semi-colon. Nate lol now i feel like a dummie but now its showing up blank screen again ??? 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.