Endless Paradigm

Full Version: looking for a PHP download script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
[Image: tumblr_l56uxbDvTa1qz98a1o1_500.jpg]
nurehtix Wrote: [ -> ][Image: tumblr_l56uxbDvTa1qz98a1o1_500.jpg]

Yay
you could have the download link bring you to a page that has the php code in it, then have the php code download the file, then if they right click and hit save as, it will save the php page
so just in case someones confusesd itll go
download link > php page > php page downloads automatically

so if they right click, theyll actualy donload this
                         |
                         V
download link > php page > php page downloads automatically

instead of that ---------------------|
                                                  V
download link > php page > php page downloads automatically




happy now?
haha! That is brilliant!

except it totally didn't work like that. :(

download.php =

PHP Code:
<?php
	include 'get.php';
?>


and get.php is the script I posted earlier.

It downloads the file correctly, but 'Save As' still works. :(

poop!

nurehtix Wrote: [ -> ]Well I don't really care  if it always works, I'd just like to thwart the average user.

Really, the only reason I'm bothering is to track downloads; to see how many people are downloading our releases, and the tracking script is an 'onclick' one.
Then you're doing it the wrong way.
The PHP script should be counting downloads, JS really shouldn't be tracking downloads.
Perhaps have a little .txt file with the number of downloads stored there, and update it every time a download is hit.

Actually, best method would be just to provide a direct link and count downloads via webserver logs.
With this, you also don't have problems with pausing/resuming downloads, as well as multipart downloading, since the webserver handles all this, but your script doesn't.

By the way, your PHP script needs to check inputs more.
Otherwise, stuff like this works: http://deletefunction.com/download.php?f...wnload.php
Probably not an issue for you, but if you ever put stuff you don't want others to see, you may want to be aware of it.
ZiNgA BuRgA Wrote: [ -> ]Then you're doing it the wrong way.
The PHP script should be counting downloads, JS really shouldn't be tracking downloads.
Perhaps have a little .txt file with the number of downloads stored there, and update it every time a download is hit.

Actually, best method would be just to provide a direct link and count downloads via webserver logs.
With this, you also don't have problems with pausing/resuming downloads, as well as multipart downloading, since the webserver handles all this, but your script doesn't.

Well, I'm actually tracking downloads with Google Analytics right now, but if there's a better way, feel free to show me. :D

EDIT: I changed the download.php a bit, so it (kind of) tracks downloads. See below:

ZiNgA BuRgA Wrote: [ -> ]By the way, your PHP script needs to check inputs more.
Otherwise, stuff like this works: http://deletefunction.com/download.php?f...wnload.php
Probably not an issue for you, but if you ever put stuff you don't want others to see, you may want to be aware of it.

lmao.

I'll do something simple:

PHP Code:
<?php
	$file=$_GET["file"];

	if($file=="DF001.zip")
	{
		$hits = file_get_contents("df001.txt");
		$hits = $hits + 1;
		$handle = fopen("df001.txt", "w");
		fwrite($handle, $hits);
		fclose($handle);
		include 'get.php';
	}
	elseif($file=="DF002.zip")
	{
		$hits = file_get_contents("df002.txt");
		$hits = $hits + 1;
		$handle = fopen("df002.txt", "w");
		fwrite($handle, $hits);
		fclose($handle);
		include 'get.php';
	}
	else
		die("LOL");
?>

Better:

PHP Code:
<?php
	switch($_GET["file"]) {
		case "DF001.zip":
		case "DF002.zip":
			$hitsfile = substr($_GET["file"], 0, -4) . '.txt';
			if($fp = @fopen($hitsfile, 'r+')) {
				flock($fp, LOCK_EX); // prevent two simultaneous downloads corrupting the file
				$hits = intval(fgets($fp)) +1;
				rewind($fp);
			} else {
				// file doesn't exist, create it
				$hits = 1;
				($fp = @fopen($hitsfile, 'w')) or die('Can\'t write file');
				flock($fp, LOCK_EX);
			}
			fputs($fp, strval($hits));
			flock($fp, LOCK_UN);
			fclose($fp);
			
			include 'get.php';
			
			break;
		default:
			header('HTTP/1.1 404 Not Found');
			
	}

?>

Awesome, thanks much, Zinga.

Woo
use javascript to disable right click?
I almost considered going that route, but that annoys the spoon out of me when a website is like that. :p
Pages: 1 2 3
Reference URL's