downThemAll Firefox addons

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
chandra prakash
Posts: 4
Joined: January 12th, 2017, 11:44 pm

Post Posted January 12th, 2017, 11:59 pm

Hello everyone,

I develop a PHP code and count how much data was downloaded by the client. My code is working fine if someone directly requests my file from a browser. But if someone installs a Mozilla extensions like ‘’downthemall’’ and then the url is requested by that extension then it requests the file URL 4 times so I get the downloaded data 4 times. How do I fix this? The same happened when the user is using jDownloader software or any software.

Code: Select all
function getMimeType($fileName)
    $c_type_default = "application/octet-stream";
    $content_types = array(
        "exe" => "application/octet-stream",
        "zip" => "application/zip",
        "mp3" => "audio/mpeg",
        "mpg" => "video/mpeg",
        "avi" => "video/x-msvideo",
       "mp4" => "video/mp4",
//    echo isset($content_types[pathinfo($fileName, PATHINFO_EXTENSION)]) ? $content_types[pathinfo($fileName, PATHINFO_EXTENSION)] : $c_type_default;     
    return isset($content_types[pathinfo($fileName, PATHINFO_EXTENSION)]) ? $content_types[pathinfo($fileName, PATHINFO_EXTENSION)] : $c_type_default;
function output_file($file, $name)
 This function takes a path to a file to output ($file),  the filename that the browser will see ($name) and  the MIME type of the file ($mime_type, optional).
 //Check the file premission
 if(!is_readable($file)) die('File not found or inaccessible!');
 $size = filesize($file);
 $name = rawurldecode($name);

 //turn off output buffering to decrease cpu usage
   // Start Code  For Total Downloaded Data Size by The LoggedIn User
       $user="select * from $TBusers where id=".$_SESSION['log_id'];
      $result_user = mysqli_query($conn, $user) ;
      $row = mysqli_fetch_assoc($result_user);
       $lastsotrage = $row['down']; 
       $curr_date= $row['curr_date'];
       $today_date= date('d-m-y');
       $daily_downloaded_data= $row['daily_downloaded_data'];
      if($curr_date != $today_date)
           $update_curr_date="update $TBusers set curr_date ='$today_date', daily_downloaded_data =0 where id=".$_SESSION['log_id'];  // Set Curr_date by Today Date For check Daily Downloaded Data Limit
           mysqli_query($conn,$update_curr_date) ;
          if($daily_downloaded_data>=(20*1024*1024*1024)){          // Check Daily  Download Data Limit 20GB Exceed or not

 // required for IE, otherwise Content-Disposition may be ignored
 ini_set('zlib.output_compression', 'Off');
 header('Content-Type: ' . getMimeType($name));
 header('Content-Disposition: attachment; filename="'.$name.'"');
 header("Content-Transfer-Encoding: binary");
 header('Accept-Ranges: bytes');
 /* The three lines below basically make the
    download non-cacheable */
 header("Cache-control: private");
 header('Pragma: private');
 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
 // multipart-download and download resuming support
   list($a, $range) = explode("=",$_SERVER['HTTP_RANGE'],2);
   list($range) = explode(",",$range,2);
   list($range, $range_end) = explode("-", $range);
   if(!$range_end) {
   } else {

   $new_length = $range_end-$range+1;
   header("HTTP/1.1 206 Partial Content");
   header("Content-Length: $new_length");
   header("Content-Range: bytes $range-$range_end/$size");
 } else {
   header("Content-Length: ".$size);
 /* Will output the file itself */
 $chunksize = 1*(1024*1024); //you may want to change this
 $bytes_send = 0;
 if ($file = fopen($file, 'r'))
   fseek($file, $range);
   while(!feof($file) &&
      (!connection_aborted()) &&
      $buffer = fread($file, $chunksize);
      print($buffer); //echo($buffer); // can also possible
      $bytes_send += strlen($buffer);
          $lastsotrage= $lastsotrage + $size;
          $sql="update $TBusers set down =". $lastsotrage." where id=".$_SESSION['log_id'];
         $sql2="update $TBusers set daily_downloaded_data = $daily_downloaded_data where id=".$_SESSION['log_id'];
         $sql3= "update test set count=count+1 where id=1" ;
         mysqli_query($conn,$sql) ;
         mysqli_query($conn,$sql2) ;mysqli_query($conn,$sql3) ;
         file_put_contents('data.txt', print_r($_SERVER, true), FILE_APPEND);
 } else
 //If no permissiion
 die('Error - can not open file.');
//Set the time out

//path to the file
$file_name = str_replace("/", "", $_GET['file']);
$file_name = str_replace("\\", "", $file_name);
$file = $file_dir . "/".$file_name;

//Call the download function with file path,file name and file type
output_file($file, ''.$file_name.'');

Last edited by chandra prakash on January 16th, 2017, 11:34 pm, edited 1 time in total.


User avatar
Posts: 125159
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Post Posted January 13th, 2017, 5:12 am

Moving to Web Development.


User avatar
Posts: 2135
Joined: May 5th, 2004, 10:40 am
Location: Belgium

Post Posted January 14th, 2017, 5:30 am

Are you sure it increases the download data? Just hits doesn't mean anything. It's possible that it's simply using concurrent connections, where the first connection downloads the first 25%, the second connection simultaneously downloads from 25-50%, and so on.
Intelligent alien life does exist, otherwise they would have contacted us.

chandra prakash
Posts: 4
Joined: January 12th, 2017, 11:44 pm

Post Posted January 16th, 2017, 11:37 pm

I make a table into database and update a filed on by 1 when it update database.
but it updateed the filed 4 times on a single download so i think it hit 4 times.

if it use concurrent connections and hit 4 times then i want to make it only one time because it updated my data 4 times.

Return to Web Development / Standards Evangelism

Who is online

Users browsing this forum: No registered users and 2 guests