Jump to content

Recommended Posts

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

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));
?>

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);
?>

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.

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