voip03 Posted August 6, 2011 Share Posted August 6, 2011 1st time this code will not start download, but when I refresh it will start downloading. Why is that? <? session_start(); require("config.php"); ini_set('memory_limit', '-1'); //download/ECDL.zip $dir="download/ECDL.zip"; $file=$dir; $query=mysql_query("select * from filestats where filename='".basename($file)."' LIMIT 0,1") or die (mysql_error()); $fileexist=@mysql_num_rows($query); $now=date("Y-m-d G:i:s"); if ($fileexist>0) { $updatequery=mysql_query("update filestats set downloads=downloads+1, lastdownload='$now' where filename='".basename($file)."'") or die (mysql_error()); } else { $addquery=mysql_query("insert into filestats (filename,downloads,lastdownload) values ('".basename($file)."','1','$now')") or die (mysql_error()); } //get ip address... if(!empty($_SERVER['HTTP_CLIENT_IP'])) { // share internet $ip=$_SERVER['HTTP_CLIENT_IP']; $ip .= "/S"; } elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { // pass from proxy $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; $ip .= "/P"; } else { $ip=$_SERVER['REMOTE_ADDR']; $ip .= "/O"; } $sql = "INSERT INTO downloadUserIP( date, userID, ProductID,IP ) VALUES ( NOW(),'".$_SESSION['SESS_USERID']."','".$a."','".$ip."');"; $res = mysql_query($sql); if(!$res) { die(" Could not query the database customers 24 : <br/>". mysql_error() ); } header("Content-type: application/force-download"); header("Content-Transfer-Encoding: Binary"); header("Content-length: ".filesize($file)); header("Content-disposition: attachment; filename=".basename($file)); readfile("$file"); ?> Link to comment https://forums.phpfreaks.com/topic/244028-something-wrong-in-my-code/ Share on other sites More sharing options...
phpSensei Posted August 6, 2011 Share Posted August 6, 2011 These stuff tend to be problematic all the time, what browser are you using? Also you need to apply a Cache-Control. Link to comment https://forums.phpfreaks.com/topic/244028-something-wrong-in-my-code/#findComment-1253192 Share on other sites More sharing options...
voip03 Posted August 6, 2011 Author Share Posted August 6, 2011 IE8 Link to comment https://forums.phpfreaks.com/topic/244028-something-wrong-in-my-code/#findComment-1253201 Share on other sites More sharing options...
voip03 Posted August 6, 2011 Author Share Posted August 6, 2011 ' Cache-Control' can you point me , wher to go OR sHow to do. Link to comment https://forums.phpfreaks.com/topic/244028-something-wrong-in-my-code/#findComment-1253208 Share on other sites More sharing options...
phpSensei Posted August 6, 2011 Share Posted August 6, 2011 Disabling the cache boils down to the browser being used, it seems that some browser's need different header paremeters... Can't guarantee this will work. <?php // prevent caching (php) header('Cache-Control: no-cache'); header('Pragma: no-cache'); header('Expires: ' . gmdate(DATE_RFC1123, time()-1)); ?> Link to comment https://forums.phpfreaks.com/topic/244028-something-wrong-in-my-code/#findComment-1253216 Share on other sites More sharing options...
voip03 Posted August 6, 2011 Author Share Posted August 6, 2011 it is not working thank u 4u'r help Link to comment https://forums.phpfreaks.com/topic/244028-something-wrong-in-my-code/#findComment-1253242 Share on other sites More sharing options...
phpSensei Posted August 6, 2011 Share Posted August 6, 2011 It wasn't intended for your download refresh problem Voip3 Link to comment https://forums.phpfreaks.com/topic/244028-something-wrong-in-my-code/#findComment-1253243 Share on other sites More sharing options...
voip03 Posted August 6, 2011 Author Share Posted August 6, 2011 can u point me one direction thank u Link to comment https://forums.phpfreaks.com/topic/244028-something-wrong-in-my-code/#findComment-1253500 Share on other sites More sharing options...
phpSensei Posted August 6, 2011 Share Posted August 6, 2011 I tested this one, it works on all versions of IE6, IE7, IE8, Firefox, Opera, and Chrome <?php // Make sure program execution doesn't time out set_time_limit(0); $mtype = "application/force-download"; $fname = 'filename.ext'; // set headers header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=\"$fname\""); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . $fsize); ?> Link to comment https://forums.phpfreaks.com/topic/244028-something-wrong-in-my-code/#findComment-1253502 Share on other sites More sharing options...
voip03 Posted August 7, 2011 Author Share Posted August 7, 2011 It is working but only download 1bytes ? Link to comment https://forums.phpfreaks.com/topic/244028-something-wrong-in-my-code/#findComment-1253742 Share on other sites More sharing options...
phpSensei Posted August 8, 2011 Share Posted August 8, 2011 i believe its because of this line: ); header("Content-Length: " . $fsize); Link to comment https://forums.phpfreaks.com/topic/244028-something-wrong-in-my-code/#findComment-1253972 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.