PHP - How To Add Download Counter To My Code
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 Similar TutorialsI 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. Hi 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. How can i make this hit counter code, so that it doesnt update the views on ALL of my videos. i want it to be unique for each video id. any ideas? Code: [Select] <?php $querySelect = mysql_query("SELECT * FROM `mydatabase` WHERE `counter`"); $row = mysql_fetch_assoc($querySelect); $counter = $row['counter']; if (empty($counter)) { $counter = 1; $insert = mysql_query ("INSERT INTO counter VALUES ('counter')"); } $add = $counter+1; $insertNew = mysql_query("UPDATE mydatabase SET counter=('$add')"); echo "Video Views"; echo ":"; echo" "; echo"<br />"; echo "$counter"; ?> www.game4vids.com if you pick a video you can see that it changes the views on ALL the videos i have. How can I create a PHP script that will trigger a download?
For example, if I have a database of files and file IDs, and have a hyperlink like this in an HTML page:
getfile.php?FileID=1001
How can I code the getfile.php file so that no matter what type the file is (ZIP, EXE, JPG, AVI, etc), it will cause the browser to prompt the user to download the file?
(Not entirely sure if this is more a PHP question or an HTML question because of how I'm approaching it...)
(The purpose of me using the getfile.php file is so that files can be physically moved around without me having to update all of the hyperlinks in the HTML files, but rather just update the paths in the SQL database instead.)
Edited by cbassett03, 02 September 2014 - 11:25 PM. I'm trying to create a series of images on a page but the code won't run. (left table code out): <body> <?PHP /// fyi, the image_link field contains, e.g., artistfoldername/imagefilename.jpg $path = "artWorkImages/"; $art_id ='2'; $QUERY="SELECT art_title, about_art, image_link FROM artWork WHERE art_id = '$art_id'"; $res = mysql_query($QUERY); $num = mysql_num_rows($res); if($num>0){ while($row = mysql_fetch_array($res)){ $artist_name = $row["art_title"]; $about_art = $row["about_art"]; $image_link = $row["image_link"]; print "<img src=$path.$image_link/>"; } } ?> </body> Thanks Allen I have a webpage where the candidates can attach their resumes and send to the admin.These attachments are saved in the mysql db as blob datatype.In another webpage the admin needs to download all this resumes and see the content. How will i code for that.
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
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 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 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); } 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
<?php $counter_name = 'Counter.txt'; if (!file_exists($counter_name)) { $f = fopen($counter_name, "w"); fwrite($f,"0"); fclose($f); } $f = fopen($counter_name,"r"); $counterVal = fread($f, filesize($counter_name)); fclose($f); $counterVal++; $f = fopen($counter_name, "w"); fwrite($f, $counterVal); fclose($f); echo $counterVal; ?> This is click counter... Counter.txt only number... How to add a date? Counter / Date 1. 2021-02-28 19:50:47 2. 2021-02-23 17:57:11 etc
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 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 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! I am trying to keep track of how many times a page is loaded for debugging. Here is my code but it doesn't seem to work?! Code: [Select] <?php isset($counter) ? $counter++ : $counter=1; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Page A</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <h3>Add a Comment</h3> <form action="Processing.php" method="post"> <fieldset> <!-- Comment --> <label>Comment:</label><br /> <textarea cols="50" rows="15"><?php echo $counter; ?></textarea> <br /> <!-- Submit Form --> <input type="submit" name="addComment" id="addComment" value="Add a Comment"/> </fieldset> </form> </body> </html> What am I doing wrong? Debbie |