Author Topic: Show downloaded stats at image  (Read 3071 times)

0 Members and 1 Guest are viewing this topic.

Offline rymo

  • Pre-Newbie
  • Posts: 5
    • View Profile
Show downloaded stats at image
« on: April 11, 2008, 11:51:23 PM »
Hello,

I'd like to show user and date downloaded, upon clicking the download button of an image.

ex. "This image has been downloaded by ---- on ----."

If anyone is able to shed a bit of light, it is appreciated, as I'm getting my hands dirtly, but by no means a php expert.

Offline rymo

  • Pre-Newbie
  • Posts: 5
    • View Profile
Re: Show downloaded stats at image
« Reply #1 on: August 19, 2008, 02:14:52 AM »
I've gotten some php coding into this previous request, but would like to ask for any guidance on continuing to get this going.

I'm mainly working in 2 files: includes/functions.php and download.php, where I believe my php coding if off. Otherwise, I have everything else set up to make this happen in other relevant files, having been guided by the Keep Track of What Each User Has Downloaded thread (http://www.4homepages.de/forum/index.php?topic=4606.0).

My code in download.php:
After the send file function, ending with:
Code: [Select]
  else {
    ereg("(.+)\.(.+)", get_basefile($image_row['image_media_file']), $regs);
    $file_name = $regs[1];
    $file_extension = $regs[2];

    $file['file_name'] = $file_name.(($size) ? "_".$size : "").".".$file_extension;
    $file['file_path'] = (is_local_file($image_row['image_media_file'])) ? dirname($image_row['image_media_file'])."/".$file['file_name'] : MEDIA_PATH."/".$image_row['cat_id']."/".$file['file_name'];
  }

I inserted:
Code: [Select]
$downloaded_users = $image_row['user_id'];
$users_array = explode(" ", $downloaded_users);
if (in_array($user_id, $users_array)) {
$downloaded_users = $download_user_name;
}

if (!empty($image_row['image_downloads'])) {
  $site_template->register_vars(array(
"download_user_name" =>   $download_user_name,
        "download_date" => date("M d, Y", $download_date),
"comment_user_email_button" => $comment_user_email_button
));
$image_downloaded = $site_template->parse_template("downloaded_bit");
}


In function.php:
Inserted at very end of file before the php close tag:
Code: [Select]
function add_to_download_date($id) {
  $download_date = $image_row['download_date'];
 
$sql = "UPDATE ".IMAGES_TABLE."
            SET download_date = time()
            WHERE image_id = $image_id";
      return ($site_db->query($sql)) ? 1 : 0;
}

Other files/relevant changes which have seemed to be fine:
- I've set up a db row in the image table entitled "download_date"
- details.html has link to copy which is linked from a new file "downloaded_bit.html"

Thank you kindly, ready to give any other info I can, tomorrow.... need to leave for the night.