I got a file on my server, for example: http://www.site.com/file.zip I want to limit the download on the file to 20 downloads, and after that it cant be downloaded. How can i do that? Thanks.
Hi there, you can limit downloads using zen shopping cart - free software on cpanel or by using a software like DL Guard - it is $127 and you can use it on two domains also as a membership site. Hope that helps
I dont think that is what i want...I might be wrong.. still looking for something that does what i want.
If I understand you correctly, you want to limit the download of each file to some number of downloads (like 20). The only way to do what you are asking about is thru a script on the server. How are people downloading files now? Is it thru a link on a web page? If so, what scripting language are you using? PHP. Perl, CGI, something else? You can PM me with further info, if you like.
pakh: I coded a small PHP program to watch for the GET and tag +1 to a counter in mysql based off IP address. Very simple program and I would recommend doing it this way. Zencart and other solutions are valid as well but I am a homebrew guy myself. You can watch for various things. Obviously if your watching via IP address then they can change hosts and download some more. On my Fre FOnts site i watch for 5 downloads then force them to signup in which they get unlimited downloads. All free. Just basically getting the email addy from them.
If you are using apache, then you can do it with mod_limitipconn module. This module allows you to limit downloads from a location on the server per IP based.
And if you are using vbulletin as the download medium, there is a plugin called Link And Download manager which you can set whatever you want including limit per day/month/year etc.
i am not using anything special, just using the direct link: site.com/file.zip But if i can do something to the file so it doesnt get downloaded more than 20 times. What is the best way of doing this? Anything easy, as i am not an expert on php, apache, etc
The way I would do it is to add a rewrite rule that called a php script rather than the actual file. RewriteRule /file.zip /downloadfile.php [NC,L] Code (markup): Then, in the downloadfile.php I would put some code that checked the number of times the file had been downloaded and either give them the file or give them an error message. Something like this should work but beware, I am writing this code without running it... it may not compile You will definitely want to look up the correct mime-type header for zip files because I have no idea what it should be. <?php // If the counter is more than 24 hours old, zero it. if(filemtime("counter.txt") - time() < (60 * 60 * 24)) { file_put_contents("counter.txt", "0"); } // Find out how many people have downloaded today. $counter = file_get_contents("counter.txt"); // If more than twenty, give an error message. // If 20 or fewer downloads, give them the file. if($counter > 20) { include("too_many_downloads.html"); exit(); } else { // Increment the file counter... file_put_contents("counter.txt", $counter + 1); // Send the right mime-type header. header("Mime-type: application/zip"); // Send the file. echo(file_get_contents("file.zip")); } ?> PHP: Don't forget, PHP.net is your friend.
Just tried the code above as I need exactly the same as pakh. I get a "PHP Fatal error: Call to undefined function: file_put_contents() in C:\Servers\WWW\Root\download\get.php on line 5". Any clues? I'm using PHP4.
file_put_contents isn't available before php5. You'll have to use one of the emulated functions found in the comments on the manual page.
<?php if (!function_exists('file_put_contents')) { function file_put_contents($filename, $data, $respect_lock = true) { // Open the file for writing $fh = @fopen($filename, 'w'); if ($fh === false) { return false; } // Check to see if we want to make sure the file is locked before we write to it if ($respect_lock === true && !flock($fh, LOCK_EX)) { fclose($fh); return false; } // Convert the data to an acceptable string format if (is_array($data)) { $data = implode('', $data); } else { $data = (string) $data; } // Write the data to the file and close it $bytes = fwrite($fh, $data); // This will implicitly unlock the file if it's locked fclose($fh); return $bytes; } } ?> Code (markup): Use this function in a file or include it from another file. Enjoy!
Sorry, but i dont understand... Do i put this code in a .php file? Where do i edit the filename in that code?