NameSilo

One questions about programming an image hosting...

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
NamecheapNamecheap
Watch

cuongdm

Established Member
Impact
0
hi,
I am using PHP to code my image hosting project...
And i want to know "how many times an image is downloaded?"
cause we have to give our members a link like:
--------------
http://.../imagename.jpg
not like
http://..../view.php?name=imagename.jpg
-----------------
Now I can't calculate exactly how much bandwidth a member used,
need your helps...
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains — AI StorefrontUnstoppable Domains — AI Storefront
you need an "out" page...

the out page needs to work like this:

1. The user clicks a link to out.php?img=##URL TO IMAGE HERE##
2. Script checks to see if image is there first
3. If image is there it gets [from a database] a number corresponding to the amount of people who have clicked through that link to that image
4. Script adds "1" onto that number and re-inserts it into the database
5. Script redirects to image page

script would look something like:
PHP:
<?php

$img = $_REQUEST['img']; // gets the "img" variable from the querystring

if(!file_exists("path/to/folder/".$img)){ // if the image isn't there...
Header("Location: error_404.php"); // redirect to error page
}

// connect to mysql db now
$dbl = mysql_connect("host","username","password");
mysql_select_db("db_name", $dbl);

// you need a table first... the table just needs the fields "image" and "number"
// "image" needs to hold the name of the image (ie: pic.jpg)
// "number" needs to hold the number of times it has been downloaded
$result = mysql_query("SELECT number FROM table_name WHERE image=$img");
$num = mysql_num_rows($result);

if($num != 1){
Header("Location: error_mysql.php");
}

$i = $result++ // increment $result

$var = mysql_query("UPDATE table_name SET (number) ($i) WHERE image=$img"); // my UPDATE code is not up to scratch lol

if($var){ // if $var returned TRUE
Header("location: path/to/folder/".$img); // redirect to image
}

?>
 
0
•••
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back