• 0

Download.php with log?


Question

Hello!

I am looking for a simple download.php file that can log how many times a file has been downloaded.

The download URL would ideally be like: http://www.mysite.com/download.php?id=13

Somewhere in the file it would see what file 13 is and link to it (hiding the actual file location). I am not sure how to do this, I tried using the GET command but then it needed to know why type the file was, so i got stuck again <-- PHP noob! :pinch:

Thanks,

Peter

Link to comment
https://www.neowin.net/forum/topic/414776-downloadphp-with-log/
Share on other sites

13 answers to this question

Recommended Posts

  • 0

 &lt;?php ob_start;
// ids
$1 ="download/downloadname.zip";
$2 ="download/downloadname.zip";
$3 ="download/downloadname.zip";
$4 ="download/downloadname.zip";

// find download no
$download ="$".$_GET['id'].""

// Add one to the counter file, then close it.
	$countOpen = fopen($dir['exp'] . "download/logs/counter".$_GET['id'].".txt", "r");
	$oldCount = fread($countOpen, 1024);
	fclose($countOpen);
	$newCount = $oldCount + 1;
	$countOpen = fopen($dir['exp'] . "download/logs/counter".$_GET['id'].".txt", "w");
	fwrite($countOpen, $newCount);
	fclose($countOpen);

	header("Location: http://www.mysite.com/".$download 



?&gt;

How use

make the following folers

download/

download/logs/

edit the download no's

put all your downloads in download/

make a txt file for each log in logs eg "counter1.txt" and put 0 inside it IMPORTANT you must put 0 and ONLY 0

chmod the txt files 777 !IMPORTANT

then use the script as mysite.com/download.php?id=1

now i just put this together so if it errors contact me on msn

  • 0

Shame i cant edit :/

Could I possibly change the IDs to names instead of numbers?

I tried but it gave me a: Parse error: parse error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in /home2/mak0sch/public_html/download.php on line 4

$2 ="download/downloadname.zip";

Then, when chaging ALL of them to names I got:

Parse error: parse error, unexpected T_STRING in /home2/mak0sch/public_html/download.php on line 20

header("Location: http://www.wizzyworld.com/".$download

Although, when using all numbers, I get:

Parse error: parse error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in /home2/mak0sch/public_html/download.php on line 3

So, in short the script doesnt work?

I took out the logs (for now) so now my script looks like:

&lt;?php ob_start;
// ids
$1 ="download/PathCopyEx.msi";
$2 ="download/downloadname.zip";
$3 ="download/downloadname.zip";
$4 ="download/downloadname.zip";

// find download no
$download ="$".$_GET['id'].""

// Counter Code: Add one to the counter file, then close it.
/*	$countOpen = fopen($dir['exp'] . "download/logs/counter".$_GET['id'].".txt", "r");
	$oldCount = fread($countOpen, 1024);
	fclose($countOpen);
	$newCount = $oldCount + 1;
	$countOpen = fopen($dir['exp'] . "download/logs/counter".$_GET['id'].".txt", "w");
	fwrite($countOpen, $newCount);
	fclose($countOpen); */

	header("Location: http://www.wizzyworld.com/".$download

?&gt;

Although when the script it working, I plan to customise it a little, such as instead of using "id" as the "GET name, I shall use "file" or something.

Also, is there a way that I can make a viewable page when users go to the URL: "http://www.mysite.com/download.php"? Something like a redirect to the real download page or something?

  • 0

Well, the problem you are having is because you cannot start a variable name with a number. You need to start the variable names with an _ (underscore) or a letter for them to be valid. Probably a result of trying to throw something together too quickly or poor coding...

  • 0

I don't know if this will work, but try this :

 
&lt;?php ob_start;
// id parser
if($_GET['id'] ==1)
 {$download ="$"."download/PathCopyEx.msi"."";}
  else{
		  if($_GET['id'] ==2)
			 $download ="$"."download/downloadname.zip"."";
			   else
			   {
				 if($_GET['id'] ==3)
					$download ="$"."download/downloadname.zip"."";
					  else{
							  if($_GET['id'] ==4)
								 $download ="$"."download/downloadname.zip"."";
								   else
										 $download =""

							 }
				}
		   }




// Counter Code: Add one to the counter file, then close it.
/*	$countOpen = fopen($dir['exp'] . "download/logs/counter".$_GET['id'].".txt", "r");
	$oldCount = fread($countOpen, 1024);
	fclose($countOpen);
	$newCount = $oldCount + 1;
	$countOpen = fopen($dir['exp'] . "download/logs/counter".$_GET['id'].".txt", "w");
	fwrite($countOpen, $newCount);
	fclose($countOpen); */

	header("Location: http://www.wizzyworld.com/$download");
	exit;
?&gt;

  • 0
  2shae said:

i can do something in mysql instead if u add me to msn,

2shae.mail@gmail.com

I would BUT i don't really like adding people to MSN as i use it for personal friends only really :/

Script Problem:

Parse error: parse error, unexpected '}' in /home2/mak0sch/public_html/download.php on line 18

which is the first "}" in the set of three.

I am really suprised how many coders there are here and nobody has a script they use or anything.

It makes it more complicated as sites which do have a "download.php" file dont really have it. I asked but nobody really knew here. To get a general idea on how it works then I want to see the source to the "download.php" file, so i use FlashGet to download the "download.php" file but when i do all it is is HTML telling me that i havent selected a downlaod ID - so how are they doing that?!

A good example of this is HERE. If you go to the catdb.php file then it doesnt show the code. I know this is security for the site but how is it done? Nobody here knows?

However, using Google and keywords that I didnt use before turned up: http://elouai.com/force-download.php

This (I think) will do the above, show a user a page if they didnt link to a proper download.

Peter

Edited by TheTrainMan
  • 0

i can do something in mysql instead if u add me to msn,

2shae.mail@gmail.com

ok i wrote and tested this

download.php

&lt;?php //ob_start;
//

$download1 = "mysite.com/downloads/";
$username = "";
$password = "";
$databasename = "download";
$databaseip = 'localhost';
// find download no

$d1 = "".$_GET['id']."";
// mysql connect
mysql_connect ($databaseip, $username, $password);
mysql_select_db ($databasename);
$sql = mysql_query ("select* from downloads where id = $d1");
$results = mysql_fetch_array($sql);
$name = $results["name"];
// Counter Code: Add one to the counter file, then close it.
/*	$countOpen = fopen($dir['exp'] . "download/logs/counter".$_GET['id'].".txt", "r");
	$oldCount = fread($countOpen, 1024);
	fclose($countOpen);
	$newCount = $oldCount + 1;
	$countOpen = fopen($dir['exp'] . "download/logs/counter".$_GET['id'].".txt", "w");
	fwrite($countOpen, $newCount);
	fclose($countOpen); 
*/

$downloadurl = $download1.$name;


 header("Location: ".$downloadurl."");

?&gt;

in the sql database

-- phpMyAdmin SQL Dump
-- version 2.7.0-pl2
-- http://www.phpmyadmin.net
-- 
-- Host: localhost
-- Generation Time: Jan 11, 2004 at 07:03 PM
-- Server version: 4.1.14
-- PHP Version: 4.4.1
-- 
-- Database: `download`
-- 

-- --------------------------------------------------------

-- 
-- Table structure for table `downloads`
-- 

CREATE TABLE `downloads` (
  `id` longtext NOT NULL,
  `name` longtext NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- 
-- Dumping data for table `downloads`
-- 

INSERT INTO `downloads` VALUES ('1', 'download1.zip');
INSERT INTO `downloads` VALUES ('2', 'download2.zip');

follow the instructions that were on my post before

you will get errors if you dont have ?id=1 etc at the end

you can add new download names via phpmyadmin

  • 0

Hmm. This means I have to make a form to add stuff into the MySQL Database which I'm not that familiar with. I dunno, i am so sick of trying to get one to work, i've been through files that download blank files and downloads that show blurb on the page instead of downloading the actual file. . . lol, i am quite sick of this today. However, your code has not been i vein, I have saved it and will try it out later.

I also found this:

&lt;?php

$filename = $_GET['file'];
$path="files/";

/*print "filename ".$filename;
print "path ".$path;*/

header('Pragma: private');
header('Cache-control: private, must-revalidate');
header("Content-type: text/x-ms-iqy"); 

$fp = fopen($path.$filename,"r"); 
$filedata=fread($fp,filesize($path.$filename)); 
fclose($fp); 

header("Content-type: text/x-ms-iqy"); 
header("Content-Disposition: attachment; filename=".$filename); 
print $filedata; 

?&gt;

Although when downloading something, it doesnt want to show a progress bar, nor does it want to tell me what type of file it is.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Sorry to say but much like the upcoming phones not interesting at all
    • Latest leak spills potential details about the upcoming Google Pixel Watch 4 by Sagar Naresh Bhavsar Google is set to officially unveil the Pixel 10 series and the Pixel Watch 4 on August 20. The company shared a teaser video on YouTube, confirming the date and the devices. While details about the Pixel 10 have been emerging frequently, a new leak provides information about the upcoming Google smartwatch. Reliable leaker Evan Blass has shared multiple images, appearing to be promotional materials, on the social media platform X. The images allegedly hint at what the upcoming Google Pixel Watch 4, the latest Wear OS smartwatch from the company, could have in store. First up, Google Pixel Watch 4 will come with Gemini integration, which means it will be the default assistant going forward. As per the leak, the smartwatch will come in two sizes: 45mm and 41mm, similar to its predecessor. Both variants are purported to feature Google's Actua 360 display that can hit a peak brightness of 3,000 nits, allowing for better outdoor visibility, even in extreme sunlight. While the actual battery capacity isn't revealed, the 41mm Pixel Watch 4 is tipped to offer up to 30 hours of battery life, whereas the 45mm watch will offer up to 40 hours of juice. This includes the AOD (Always On Display) enabled. Charging is also getting a boost by 25% with the Quick Charge Dock. The Google Pixel Watch 4 will come with 40+ exercise modes, ECG, SpO2, breathing rate, heart rate variability, dual-frequency GPS, and loss of pulse detection. Google will also be offering two years of LTE data for free via Google Fi Wireless service on the purchase of the LTE model. The 45mm variant of the Pixel Watch 4 is rumored to be launched in three colors, while the 41mm is shown to have an extra color. Images via Evan Blass on X
    • Here ya go : https://shop.royalmail.com/special-stamp-issues/monty-python 
  • Recent Achievements

    • Week One Done
      harveycoleman123 earned a badge
      Week One Done
    • First Post
      EzraNougat earned a badge
      First Post
    • One Month Later
      westDvina earned a badge
      One Month Later
    • Community Regular
      Bern@rd went up a rank
      Community Regular
    • Week One Done
      Joey Solo earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      664
    2. 2
      +FloatingFatMan
      196
    3. 3
      ATLien_0
      154
    4. 4
      Xenon
      132
    5. 5
      wakjak
      101
  • Tell a friend

    Love Neowin? Tell a friend!