Ankündigung

Einklappen
Keine Ankündigung bisher.

[Erledigt] Wie kann man den Download von mehreren Datein zählen?

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • [Erledigt] Wie kann man den Download von mehreren Datein zählen?

    Hallo,

    Ich arbeite zur Zeit an meiner Homepage. Dort werden auch dokumente zum downloaden angeboten. Dafür benutze ich einen downoad.php, sodass der pfad zur der datei nicht angezeigt wird (download.php?f=datei.doc). Nun, um zu zählen verwende ich uch ein php script, welches ich auch hier im Forum erhalten habe. Das problem, damit wird nur die download anzahl von einer datei gezählt, und nicht von den anderen dateien.

    Hier ist mein download.php script:
    PHP-Code:
    <?php


    define
    ('ALLOWED_REFERRER''');


    define('BASE_DIR','img/');


    define('LOG_DOWNLOADS',true);


    define('LOG_FILE','downloads.log');




    $allowed_ext = array (


      
    'zip' => 'application/zip',


      
    'pdf' => 'application/pdf',
      
    'doc' => 'application/msword',
      
    'xls' => 'application/vnd.ms-excel',
      
    'ppt' => 'application/vnd.ms-powerpoint',
      

      
    'exe' => 'application/octet-stream',


      
    'gif' => 'image/gif',
      
    'png' => 'image/png',
      
    'jpg' => 'image/jpeg',
      
    'jpeg' => 'image/jpeg',


      
    'mp3' => 'audio/mpeg',
      
    'wav' => 'audio/x-wav',


      
    'mpeg' => 'video/mpeg',
      
    'mpg' => 'video/mpeg',
      
    'mpe' => 'video/mpeg',
      
    'mov' => 'video/quicktime',
      
    'avi' => 'video/x-msvideo'
    );






    if (
    ALLOWED_REFERRER !== ''
    && (!isset($_SERVER['HTTP_REFERER']) || strpos(strtoupper($_SERVER['HTTP_REFERER']),strtoupper(ALLOWED_REFERRER)) === false)
    ) {
      die(
    "Internal server error. Please contact system administrator.");
    }


    set_time_limit(0);

    if (!isset(
    $_GET['f']) || empty($_GET['f'])) {
      die(
    "Please go to the Mainpage.");
    }


    $fname basename($_GET['f']);


    function 
    find_file ($dirname$fname, &$file_path) {

      
    $dir opendir($dirname);

      while (
    $file readdir($dir)) {
        if (empty(
    $file_path) && $file != '.' && $file != '..') {
          if (
    is_dir($dirname.'/'.$file)) {
            
    find_file($dirname.'/'.$file$fname$file_path);
          }
          else {
            if (
    file_exists($dirname.'/'.$fname)) {
              
    $file_path $dirname.'/'.$fname;
              return;
            }
          }
        }
      }

    }


    $file_path '';
    find_file(BASE_DIR$fname$file_path);

    if (!
    is_file($file_path)) {
      die(
    "File does not exist. Make sure you specified correct file name."); 
    }


    $fsize filesize($file_path); 

    $fext strtolower(substr(strrchr($fname,"."),1));


    if (!
    array_key_exists($fext$allowed_ext)) {
      die(
    "Not allowed file type."); 
    }

    if (
    $allowed_ext[$fext] == '') {
      
    $mtype '';
      
    // mime type is not set, get from server settings
      
    if (function_exists('mime_content_type')) {
        
    $mtype mime_content_type($file_path);
      }
      else if (
    function_exists('finfo_file')) {
        
    $finfo finfo_open(FILEINFO_MIME); // return mime type
        
    $mtype finfo_file($finfo$file_path);
        
    finfo_close($finfo);  
      }
      if (
    $mtype == '') {
        
    $mtype "application/force-download";
      }
    }
    else {

      
    $mtype $allowed_ext[$fext];
    }



    if (!isset(
    $_GET['fc']) || empty($_GET['fc'])) {
      
    $asfname $fname;
    }
    else {
      
    // remove some bad chars
      
    $asfname str_replace(array('"',"'",'\\','/'), ''$_GET['fc']);
      if (
    $asfname === ''$asfname 'NoName';
    }


    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Type: $mtype");
    header("Content-Disposition: attachment; filename=\"$asfname\"");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " $fsize);


    // @readfile($file_path);
    $file = @fopen($file_path,"rb");
    if (
    $file) {
      while(!
    feof($file)) {
        print(
    fread($file1024*8));
        
    flush();
        if (
    connection_status()!=0) {
          @
    fclose($file);
          die();
        }
      }
      @
    fclose($file);
    }


    if (!
    LOG_DOWNLOADS) die();

    $f = @fopen(LOG_FILE'a+');
    if (
    $f) {
      @
    fputs($fdate("m.d.Y g:ia")."  ".$_SERVER['REMOTE_ADDR']."  ".$fname."\n");
      @
    fclose($f);
    }




    ?>

    Hier ist der counter script, welches ich auch in die download.php implementiert habe:

    PHP-Code:
    $cfile $_GET['f'] . '.cnt';
    file_put_contents($cfilefile_get_contents($cfile)); 
    Und hier der code den ich auf der download seite verwende (downloadpage.php):

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Unbenanntes Dokument</title>
    </head>
    
    <body>
    <a href="/download.php?f=Footer_1.png">Here Download
    </a>
    PHP-Code:
    <?php
    echo ' (Diese Datei wurde ' intval(file_get_contents('Footer_1.png.cnt')) . ' mal gedownloadet.)';
    ?>
    Code:
    <a href="/download.php?f=background_page.gif">Here Download
    </a>
    PHP-Code:
    <?php echo ' (Diese Datei wurde ' intval(file_get_contents('background_page.gif.cnt')) . ' mal gedownloadet.)';
    ?>
    Code:
    </body>
    </html>
    Vielen Dank im Vorraus!

  • #2
    Öhm was ist jetzt das konkrete Problem? Du erstellst für jede Datei ne eigene Textdatei in der die Anzahl der Downloads gespeichert wird. Anscheinend sollte das doch funktionieren oder nicht? Wo genau liegt dein Problem?

    Kommentar


    • #3
      Zitat von Flor1an Beitrag anzeigen
      Öhm was ist jetzt das konkrete Problem? Du erstellst für jede Datei ne eigene Textdatei in der die Anzahl der Downloads gespeichert wird. Anscheinend sollte das doch funktionieren oder nicht? Wo genau liegt dein Problem?
      Die textdatei wird automatisch vom script erstellt. Das tut es auch, aber halt nur für eine Datei. Für die zweite tut es nämlich nicht. Nicht desto trotz habe ich die methode von dir uch ausprobiert, aber das hat dann auch nicht funktioniert. Deshalb habe ich es ja auch hier gepostet.

      Kommentar


      • #4
        PHP-Code:
        $cfile $_GET['f'] . '.cnt';
        file_put_contents($cfilefile_get_contents($cfile)); 
        Der Code hier erstellt aber doch für jede Datei die über $_GET['f'] angegeben wird ne eigene Textdatei, also nen eigenen Counter??

        Kommentar


        • #5
          Hab da was umgestellt. Hat jetzt alles geklappt. Vielen dank trotzdem an euch!

          Kommentar

          Lädt...
          X