• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

Download mit MySQL - Klickcounter

  • Ersteller Ersteller matibaski
  • Erstellt am Erstellt am
Status
Für weitere Antworten geschlossen.
M

matibaski

Guest
Moin!
Ich habe in eine MySQL Tabelle Downloads gespeichert, mit dem man Downloads machen kann, aber mit header();

Also der Code sieht so aus:
PHP:
    echo "<h2>Downloads</h2>";
    
    // Auslesen der Einträge
    $sql = "SELECT
                Name,
                Url,
                Klicks,
                Viesvs,
                Inhalt,
                ID
            FROM
                downloads
            ORDER BY
                Datum DESC";
    $result = mysql_query($sql) OR die(mysql_error());
    
    // Ausgeben der Anzahl von Einträgen
    echo "Downloads gesamt:" . mysql_num_rows($result) . "</p>\n";
    

    while($row = mysql_fetch_assoc($result))
    {
    
        echo '<p><fieldset style="border:1px solid black">';
        echo "<legend>".$row['Name']."</legend>\n";
        echo nl2br($row['Inhalt'])."<br />";
        echo '<div style="width:100%; height:1px; border-top:1px solid black; border:0px;"></div><br />';
        echo '<div style="float:left;">';
        echo '<a href="index.php?site=downloads&id='.$row['ID'].'">Download hier</a></div>';
        echo '<div style="float:right;">';
        echo '<a href="index.php?site=downloads&view='.$row['ID'].'">Demoversion</a></div>';
        echo "</fieldset></p>";
        
        // Downloads Updaten
        if(isset($_GET['id']))
        {
         header('Content-Disposition: attachment; filename="http://matibaski.paradoxe.de/MyB/_private/Downloads/'.$row['Url'].'"');
         $download = "UPDATE
                          downloads
                      SET
                          Klick = ''
                      WHERE
                          ID = '" . $_GET['id'] . "';
                     ";
                     
        $result = mysql_query($download) OR die(mysql_error());
         if($result)
         {
          header("Location: 'index.php?site=downloads'");
         }
        }
        // Demoversionansichten Updaten
        if(isset($_GET['view']))
        {
         $view = "UPDATE
                      downloads
                  SET
                      Viesvs = ''
                  WHERE
                      ID = '" . $_GET['id'] . "';
                 ";
                 
          if($result)
          {
           header("Location: 'index.php?site=downloads'");
          }
        }
    }
Nun habe ich 2 Fragen/Probleme:
1. Die funktion mit dem header(); funktioniert nicht.
Es ladet zwar eine Zip Datei runter, aber diese ist defekt, wenn man sie extrahieren will.
Habs mit Pfad oder URL versucht, will nicht.
Ich speichere den Namen mit Dateiart. Also Tool1.zip
Es downloadet zwar eine Zip datei, mit dem Relativen Pfad mit - statt /
Also etwa so: http-matibaski.paradoxe.de-MyB-_private-Downloads-Tool1.zip

2. Wie kann ich in eine MySQL Spalte etwas um eine Zahl höher machen?
Also sieht bisher so aus:
PHP:
        // Downloads Updaten
        if(isset($_GET['id']))
        {
         header('Content-Disposition: attachment; filename="http://matibaski.paradoxe.de/MyB/_private/Downloads/'.$row['Url'].'"');
         $download = "UPDATE
                          downloads
                      SET
                          Klick = '' // Also hier soll etwas gemacht werden
                      WHERE
                          ID = '" . $_GET['id'] . "';
                     ";
                     
        $result = mysql_query($download) OR die(mysql_error());
         if($result)
         {
          header("Location: 'index.php?site=downloads'");
         }
        }

Ich hoffe, jemand kann helfen.



MfG, matibaski
 
Also zum 2ten hier dein UPDATE-Befehl
PHP:
$download = "UPDATE
                          downloads
                      SET
                          Klick = Klick + 1 // Also hier soll etwas gemacht werden
                      WHERE
                          ID = '" . $_GET['id'] . "';
                     ";

Und beim ersten machst du es wie bei [phpnet]header[/phpnet] beschrieben ;)

PHP:
// Wir werden eine PDF Datei ausgeben
header('Content-type: application/pdf');

// Es wird downloaded.pdf benannt
header('Content-Disposition: attachment; filename="downloaded.pdf"');

// Die originale PDF Datei heißt original.pdf
readfile('original.pdf');
 
Status
Für weitere Antworten geschlossen.
Zurück
Oben