Jump to content

Something wrong in my code.


Recommended Posts

1st time this code will not start download, but when I refresh it will start downloading. Why is that?


ini_set('memory_limit', '-1'); 


$query=mysql_query("select * from filestats where filename='".basename($file)."' LIMIT 0,1") or die (mysql_error()); 
$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...
	 	// share internet 
		$ip .= "/S";
	 	// pass from proxy
		$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);
	{ 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)); 


Link to comment
Share on other sites

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.


// prevent caching (php)
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('Expires: ' . gmdate(DATE_RFC1123, time()-1));

Link to comment
Share on other sites

I tested this one, it works on all versions of IE6, IE7, IE8, Firefox, Opera, and Chrome


// Make sure program execution doesn't time out

$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
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.

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.