I have a free image upload center.Can I limit requests for files on my server from remote servers? How?
in example:
if test.png
is requested more then 1000 per day, until next day requests not accepted or redirected to other path.
It is depended on your webserver.
Yes, you can store image lists in MySQL or handle Images true PHP, but if you just need simple control files request limitation, you can do it with your webserver, also sometimes with firewall !
NGINX as I know can limited the requests accepted for special folder.
Very interesting, perhaps what you can do is:
I hope this helps
I can suggest you, with this solution:
Hope this options are useful to you, I am not attaching any code sample. Will help you afterwords.
That is possible. For every Image uploaded, have a column in the database called 'hits' or something like this.
Instead of directly serving the image, serve it trough a PHP file. Set the header content type to your image format update your counter .
A sample implementation could look like this. Note that this is not ready to use code, but you'll see yourself.
<?php
$image = $db->getWhere('images', array('img_id' => $_GET['img']));
if($image->hits >= 1000)
{
header('location: /imageviewsexceeded.php');
die();
}
header("Content-type: image/png");
$im = imagecreatefrompng('images/'.$_GET['img'].'.png');
imagepng($im);
imagedestroy($im);
$db->query('UPDATE `images` SET `hits` = `hits` + 1 WHERE `img_id` = ?', array($_GET['img']));
?>
You may want to customize your database connection and implement checks whether the image exists. But I hope it's a good place to go for you.
Happy Coding! :)