Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6958677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:10:18+00:00 2026-05-27T15:10:18+00:00

I am working on a site that allows visitors to download various documents using

  • 0

I am working on a site that allows visitors to download various documents using this code:

<input type="button" class="downloadedFile" value="Download File" onclick="window.location.href=\'documents/' . $docsRow['docFileName'] . '\'" />

$docsRow[‘docFileName’] is the path of each document, which is retrieved from a MySQL database.

The bigger picture is that these documents are in a jQuery accordion, with each accordion pane being a class with one or more documents – like such:

<div id="accordion">
<h3><a href="#">LEAD5220 - Leader as Change Agent</a></h3>
<div>
    <p class="className">Leader as Change Agent</p>
    <p class="classNumber">LEAD5220</p>
        <hr class="classSeparator" />
        <table width="95%">
            <tr>
                <td><strong>Document Name:</strong> Generic Annotation Format</td>
                <td width="100px" align="right"><input type="button" class="downloadedFile" value="Download File" onclick="window.location.href='documents/Generic Annotation Format.docx'" /></td>
            </tr>
            <tr>
                <td colspan="2"><strong>Description:</strong> This document can be used as a template for your annotations in the annotated bibliography forums.</td>
            </tr>
        </table>
        <hr class="classSeparator" />
        ...

My client wants to be able to count the number of times each document has been downloaded per class.

I known I can detect the button click via javascript, and as far as the “per class” part, I can use jQuery to detect in which class table the button clicked, but what I don’t understand is 1) how to get that info into PHP/MySQL code to record to the database, and 2) whether I can only detect the button click, or whether I can detect if the user actually downloaded the file to their computer (these are PDF, DOC, XLS files).

Thanks for anyone’s help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:10:19+00:00Added an answer on May 27, 2026 at 3:10 pm

    There are 2 options to count the number of downloads. One is to link to a php page that records every hit and than redirects to the actual file. Something like:

    <?
    $class = $_REQUEST['class'];
    $doc = $_REQUEST['doc'];
    
    // insert the code here to get and update the number of hits to this class/doc
    
    // now redirect
    header('Location: http://www.example.com/thefile.doc');
        ?>
    

    In the html the link can be something like:

    <a href="getfile.php?class=X&doc=Y">download file</a>
    

    The second approach, which I personally prefer, is to record the number of hits with ajax. When the user clicks the link to download do something like:

    $('a.thelink').click( function() {
        $.post ('getfile.php', { class: X, doc: Y });
    });
    

    this way you send the data to be recorded, and the user stays in the same page.

    If you need more clearifications let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a site that allows users to signup up. I'm currently using
I'm working on a site that allows users to purchase digital content and have
I'm working on a site that pulls various public RSS feeds down. I want
I am working on a site that lists a directory of various restaurants, and
Ok, so here's the situation. I'm working on a site that allows people to
I am working on a site that allows users to enter their phone number
I'm working on StackQL.net , which is just a simple web site that allows
I found this site that allows to convert RSS feeds into json. It also
I built a site using Drupal 6 recently that allows for users to submit
I'm working on a WordPress that will allow the site administrator to switch between

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.