PHP - Download Counter
I have music (my own) that I want to put on my website for download, and I was wondering if there is a way to keep track of how many people download each song, by tracking the clicks and displaying that number in a css-styled box. Anyone know how this is done? I don't need help with the css, just the php.
Similar TutorialsHi all, i have trouble with a piece of code. HTML: Code: [Select] <div class="psdBox"><a href="downloads/001_PSD.php"><img src="webBuild/psdIcon.png" alt="psd icon" /></a> <div class="phpBox"> <?php $hit_count = @file_get_contents('http://example.com/downloads/001_PSD.txt'); echo $hit_count; ?></div></div> PHP: <?php $url = 'http://example.com/downloads/001_PSD.txt'; $hit_count = @file_get_contents($url); $hit_count++; @file_put_contents($url); header ('Location: http://example.com/downloads/001_PSD.zip'); ?> What i'm trying to do is to count the downloads on my site using PHP without sql. This code working from the root. [www.example.com/here] But if i want this code work from a folder [www.example.com/downloads/here] then i does not work. The 001_PSD.txt won't count up from a folder. In the root, where it works, the chmod of the 001_PSD.txt is standard 0644. This works! I always thought that i must be 0777, but from the root 0644 is ok. When i tested it from /downloads folder, i tried to set 001_PSD.txt to chmod 0777, but that also fails.. Can someone help me to make this work.. i cannot find the problem, i want to make multiple downloads and don't want to put every download in the root folder.. thank, javil First off, I'm totally new to PHP. I need help on a script for a Download Counter. I have 2 programs hosted on a Web Hosting Site who does not have the facility to count the number of downloads for each program. I don't really want to learn PHP so, 1: Is there an Open Source program I can use? 2: Is there someone out there who's prepared to guide me through setting it up? Thanks in anticipation. I have a download section in my index.php that I'd like to add a download counter to but have no idea how to accomplish this. The existing code works perfectly but I'd like to know how many times the file is downloaded. Would prefer not to use a database. <!-- DOWNLOAD --> <div id="download" class="stylized"> <div "myform"> <div class="container"> <div class="row"> <div class="download"> <br /><br> <h1><center>FoxClone Download Page</center></h1> <?php $files = glob('download/*.iso'); $file = $files[count($files) -1]; $info = pathinfo($file); $filename = basename($file); $filename = ltrim($filename,'/'); $md5file = md5_file($file); ?> <div class="container"> <div class="divL"> <h3>Get the "<?php echo "{$filename}";?>" file (approx. 600MB)</h3> <center> <a href="<?php echo "/{$file}";?>"><img src="images/button_get-the-app.png" alt=""></a> </center><br /> <h3 style="margin-bottom: 0.5rem;">The MD5sum for "<?php echo "{$filename}";?>" is "<?php echo "{$md5file}";?> Thanks in advance, Larry Edited March 31, 2020 by larry29936added code tags
Basically I would like to place a link on my website and have the user download a file, but rather than just right clicking and choosing save target as, the link must be clicked, on the next page the file is fetched and then the client can download the file. How would I go about setting this up please? I have made a Php program that downloads an Inno setup installation file for installing a program. However, if I for one or another reason want to make a new download of the same Inno setup installation file, the previous file will still be found in the Download folder. Each of the downloads get a number in parenthesis, setup(1), setup(2), setup(3) etc. However, I wondered if it is posible to erase the previous file in the same process as I download a new one, so that however many downloads I do, there will all the time only be one occurence of this file in the Download folder. The download code is as follows: $exe = "Inno script/Test_setup.exe"; header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"Test_setup.exe\""); header("Content-Length: " . filesize($exe)); readfile($exe); Thanks in advance. Sincerely
how do I make $counter add one evertime it runs through the loop: Code: [Select] <?php // Query member data from the database and ready it for display $sql4 = mysql_query("SELECT * FROM labels where item_id='".$pid."'"); $num_rows = mysql_num_rows($sql4); echo $num_rows; while($row = mysql_fetch_array($sql4)){ $label =$row["label"]; $lid=$row['id']; $counter = 0; $counter = $counter + 1; print $counter . "<BR>"; ?> <select name="name<?php echo $counter; ?>"> <?php echo $label; ?>currently, it says counter is 1 everytime Hey all. Have a question, im still learning but what i am trying to do is make the number 1 add 1 to itself and repeat in the loop so, 1 2, 3, 4, 5, 6 ect...What am i doing wrong. $result = mysql_query("SELECT * FROM comments WHERE quoteid = ".$_REQUEST['quoteid'].""); while($row=mysql_fetch_array($result)){ $date = $row[date]; $name = $row[name]; $email = $row[email]; $quoteid = $row[quoteid]; $comment = stripslashes($row[comment]); $commentid = $row[commentid]; $counter = 1; $counted = $counter++; $resultb = mysql_query("SELECT * FROM quotes WHERE quoteid= '$quoteid'") or die(mysql_error()); while($link=mysql_fetch_array($resultb)){ $artist = $link[artist]; $song = $link[song]; } echo'<table border="0" cellpadding="0" cellspacing="0"><tr> <td rowspan="3" align="center"><span class="commentNumber">'.$counted.'</span></td> Hi, After looking at some Javascript, I think it can only be done in PHP. I'm trying to get my script to add a "1" to an external file. It's made in Javascript, but I hope I can put some PHP in it, even if it's at the end. I'm working on a Safari Extension, and would like to know how many people use it. It's all made in a .HTML file, so I should be able to add a PHP script at the end. I hope this is clear, and I hope it can be done in PHP, or something at least. Thanks, Joseph Duffy I have a counter that updates the database automatically with out refreshing the page. However i was wondering if someone can give me some pointers on how i can keep it updating the database even after someone exits the page. Currently it updates the database every 2 seconds by increasing the number by 1..however i want to be able to do this even if the page i not loaded is there any way i can do this? How can I say, if more than one of these if's happens do this.... Code: [Select] if ((!isset($_POST['state'])) && (($_POST['country'] != $r['country']) || ($_POST['city'] != $r['city']))) { $details = $_POST['city'].', '.$_POST['country']; update_user_actions(1, $details); } else if ((isset($_POST['state'], $_POST['city'])) && (($_POST['state'] != $r['state']) || ($_POST['city'] != $r['city']))) { $details = $_POST['city'].', '.$_POST['state']; update_user_actions(1, $details); } if ((isset($_POST['credentials'])) && ($_POST['credentials'] != $r['credentials'])) { $details = ''; update_user_actions(2, $details); } if ((isset($_POST['specialties'])) && ($_POST['specialties'] != $r['specialties'])) { $details = ''; update_user_actions(3, $details); } if ((isset($_POST['personalweb'])) && ($_POST['personalweb'] != $r['personalweb'])) { $details = $_POST['personalweb']; update_user_actions(4, $details); } hi all, i have made a counter as a module for my website. when i directly go to de module and start de counter i see the picure en he does his work, butt wen i call it in de index.php by include('modules/counter/counter.php') then i see een not loaded picturebox and i dont know why it doesnt works ? you can see the counter and the problem on: http://nieuw.pc-hulp-online.nl/index.php can someone help me to make it als work with include()?? thnx hi there i am looking to build a button counter. and i am wondering of you could help. i want the button to +1 every time someone clicks it and also store the value so it can be used as a voucher code. can anyone help thanks Hello, My hit counter doesnt work, at all. It is ment to update hits.txt(add 1 to the number in there.), and desplay how many hits it has using gd2. Here is my code: <?php /** * @author Jragon * @copyright 2010 */ getHits() function getHits() { $file = "hits.txt"; $fh = fopen($file, "r"); $hits = fread($fh, filesize("$file")); fclose($fh); ++$hits; $fh = fopen($file, "w+"); fwrite($fh, "$hits"); fclose($fh); getImage("$hits"); } function getImage($string) { //Make $string to to a string $string = "$string"; //Define fontsize $font = 5; //use imagefontwidth to find out the widht of each charicter, //then times it by how many charicters theere are, //and add some padding. $width = imagefontwidth($font) * strlen($string) + 10; //height of a charicter, and add some padding. $height = imagefontheight($font) + 10; //random color thingy. $r = rand(25, 250); $g = rand(25, 250); $b = rand(25, 250); //create a blank image using the dimsions set above. $image = imagecreate($width, $height); //set the background color $background_color = imagecolorallocate($image, 0, 0, 0); //set the text color using the random integers made above. $text_color = imagecolorallocate($image, $r, $g, $b); //Put the text into the image. imagestring($image, $font, 6, 6, $string, $text_color); //Change the type of webpage so you see the image header("Content-type: image/png"); //put everything together and make the image imagepng($image); //free up some space on the temp drive imagedestroy($image); } ?> I have created hits.txt with the value of 0 inside of it. Thanks Jragon Hi, I can't think how to make a counter which goes up during the day, and when a new day starts it gets reset to 0. How can I do this without relying on visitors to the site to run the script? Cheers, Tom. Hey everyone! My upcoming site will host, potentiallly thousands of photographs, and i was wondering how to go about having a unique ip hit counter for EACH image. Obviously i dont want people refreshing the page to gain hits, therefore the hit counter will need to be dependent on the IP address. I have used google and found a few hit counters however i need to know how to make this practical as it seems like it will require a lot of databases! Thanks in advanced, Jimmy. Ok, I'm not sure if this is even possible but I will try and explain what I want to do and then maybe someone will be able to point me in the right direction. Say I have a link to an external site like google for example, when that link is clicked the target (google in this case) will open in a new window and the page on my site remains the same, is it possible to insert data into a table in my database at the same time when the link was clicked like an id value for the link, effectively creating a count, which can be displayed somewhere on the page? I really hope that makes sense, any help would be much appreciated! So I'm trying to make a counter that counts how many times a record on mysql database has been viewed. Not a hit counter for a webpage. In other words I have a page that displays the info of that record from the mysql database and within that page I would like to display the amount of times it has been viewed. Would anyone know where I can begin or send me to a good tutorial? Thanks I'm not sure if this is the right form I may need to put this in the mySQL forum so apologies if it's in the wrong place. I would however like to do this in php. What I need to do is set up a counter that resets every day at midnight. So it would start with 01 and count up till 12:00AM server time and then reset to 01 for the next day. This is for an ordering system to add a number to the end of any order. Any help is much appreciated. I know it's not much info but I'm not even sure where to begin such a thing. Need some help on my result counter. I am using a search box to return data from my database i can get the result returned fine but i am having problems getting the total number of result returned. It only returns the number of results per page as i am using a paginate. Can some one point me in the right direction. The number count im using is below. Code: [Select] $num_rows = mysql_num_rows($sql); echo "$num_rows Results Found\n"; I know this should be easy but I cannot find right query to do this online. I simple want a counter of each result of my query. What is the proper way to query this.
For example
1 | Result 1
2 | Result 2
3 | Result 3
The one I found online did a weird grouping counter.
Thanks
|