Ankündigung

Einklappen
Keine Ankündigung bisher.

Problem mit PHP oder Apache?

Einklappen

Neue Werbung 2019

Einklappen
Dieses Thema ist geschlossen.
X
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Problem mit PHP oder Apache?

    Moin habe da ein problem den ich nicht finde:

    hab da so ein schönes script was via key ein download für eine bestimmte zeit zum download angeboten wird.

    das problem ist das eine größe datei nicht zum download anspringt normal via link zbs ne 4gb datei geht einwandfrei.

    kleine dateien macht er ja issn rätsel für mich

    weis nicht woran es liegt habe schon an der php.ini geschraubt.

    liegt es hier dran:

    header("Content-type: application/force-download");

    force-download irgenwo einstellbar in einer ini?

    oder an fast-cgi?

    thx vor help.


    hier die 2 scripts:

    Index.php

    PHP-Code:

    <?php

    $resDB 
    mysql_connect("localhost""root""Knuti");
    mysql_select_db("fusion"$resDB);

    function 
    createKey(){
        
    //create a random key
        
    $strKey md5(microtime());

        
    //check to make sure this key isnt already in use
        
    $resCheck mysql_query("SELECT count(*) FROM downloads WHERE downloadkey = '{$strKey}' LIMIT 1");
        
    $arrCheck mysql_fetch_assoc($resCheck);
        if(
    $arrCheck['count(*)']){
            
    //key already in use
            
    return createKey();
        }else{
            
    //key is OK
            
    return $strKey;
        }
    }

    //get a unique download key
    $strKey createKey();

    //insert the download record into the database
    mysql_query("INSERT INTO downloads (downloadkey, file, expires) VALUES ('{$strKey}', 'onetimedownload.zip', '".(time()+(60*60*24*7))."')");

    ?>

    <html>
        <head>
            <title>One Time Download Example</title>
        </head>
        <h1>One Time Download Example</h1>
        <p>Your unique download URL is:</p>
        <strong><a href="download.php?key=<?=$strKey;?>">download.php?key=<?=$strKey;?></a></strong>
        <p>This link will allow you to download the source code a single time within the next 7 days.</p>
    </html>


    download.php

    PHP-Code:

    <?php

    //The directory where the download files are kept - keep outside of the web document root
    $strDownloadFolder "";

    //If you can download a file more than once
    $boolAllowMultipleDownload 0;

    //connect to the DB
    $resDB mysql_connect("localhost""root""Knuti");
    mysql_select_db("fusion2"$resDB);

    if(!empty(
    $_GET['key'])){
        
    //check the DB for the key
        
    $resCheck mysql_query("SELECT * FROM downloads WHERE downloadkey = '".mysql_real_escape_string($_GET['key'])."' LIMIT 1");
        
    $arrCheck mysql_fetch_assoc($resCheck);
        if(!empty(
    $arrCheck['file'])){
            
    //check that the download time hasnt expired
            
    if($arrCheck['expires']>=time()){
                if(!
    $arrCheck['downloads'] OR $boolAllowMultipleDownload){
                    
    //everything is hunky dory - check the file exists and then let the user download it
                    
    $strDownload $strDownloadFolder.$arrCheck['file'];

                    if(
    file_exists($strDownload)){

                        
    //get the file content
                        
    $strFile file_get_contents($strDownload);

                        
    //set the headers to force a download
                        
    header("Content-type: application/force-download");
                        
    header("Content-Disposition: attachment; filename="".str_replace(" ", "_", $arrCheck['file']).""");

                        
    //echo the file to the user
                        
    echo $strFile;

                        
    //update the DB to say this file has been downloaded
                        
    mysql_query("UPDATE downloads SET downloads = downloads + 1 WHERE downloadkey = '".mysql_real_escape_string($_GET['key'])."' LIMIT 1");

                        exit;

                    }else{
                        echo 
    "We couldn't find the file to download.";
                    }
                }else{
                    
    //this file has already been downloaded and multiple downloads are not allowed
                    
    echo "This file has already been downloaded.";
                }
            }else{
                
    //this download has passed its expiry date
                
    echo "This download has expired.";
            }
        }else{
            
    //the download key given didnt match anything in the DB
            
    echo "No file was found to download.";
        }
    }else{
        
    //No download key wa provided to this script
        
    echo "No download key was provided. Please return to the previous page and try again.";
    }

    ?>







  • #2
    Hallo,

    1. die mysql* Schnittstelle ist veraltet und bei PHP7 entfernt worden. Schreibe ein i dazu, dann stimmt es wieder.
    2. Readfile ist besser, also echo. Echo könnte eventuell UTF-8 Sachen verschlucken, also nicht wirklich Binary Safe. Mehr dazu siehe hier: http://www.php.net/readfile
    3. MD5 ist nicht eindeutig, unterschiedliche Inputs können zum gleichen Hash führen. Siehe dazu uniqid: http://www.php.net/uniqid

    Vielleicht hast Du die php max execution time erreicht? Je nach Leitung des Downloaders kann das schonmal dauern. Sowas sollte doch aber auch in Deinen Server Logs stehen. Die schonmal geprüft?


    MFG

    derwunner

    Kommentar


    • #3
      jo merke schon hier werden einfach nur dumme sachen reingeklatsch als antwort. toll kann ich auch lol.
      schaue mich woanders um das board hier ist kacke.


      Kommentar


      • #4
        Was ist mir dir los?

        Du lädst eine komplette Datei in den Arbeitsspeicher und dieser ist nun mal limitiert. Wie wärs, wenn du mal Fehlermeldungen am Server liest statt hier andere Leute anzugreifen? Mal davon abgesehen, dass sogar die richtige Antwort gegeben wurde.

        Kommentar


        • #5
          Zitat von BastiHH
          toll kann ich auch lol.
          Tja.. scheinbar nicht... Schau dir lieber mal die gegebenen Tipps an, statt groß zu quatschen..


          Zitat von derwunner
          Readfile ist besser,
          statt:

          PHP-Code:
           $strFile file_get_contents($strDownload);
          // ...
          echo $strFile
          Denn, wie schon erwähnt.. RAM.. readfile macht das anders.

          Und mysql ist schon aus der aktuellen PHP Version entfernt, dh dein Scirpt wird sowieso nicht mehr lange laufen. Aber auch das ist dir ja auch egal...

          Fürs nächste Problem: Debugging lernen: https://php-de.github.io/jumpto/faq/#debugging Dann findest du deine Fehler selbst (bzw. brauchst nur lesen was PHP schreibt) und muss dich nicht in so "blöden Foren" wie hier abquälen.

          LG
          The string "()()" is not palindrom but the String "())(" is.

          Debugging: Finde DEINE Fehler selbst! | Gegen Probleme beim E-Mail-Versand | Sicheres Passwort-Hashing | Includes niemals ohne __DIR__
          PHP.de Wissenssammlung | Kein Support per PN

          Kommentar


          • #6
            [MOD: geschlossen]
            Competence-Center -> Enjoy the Informatrix
            PHProcks!Einsteiger freundliche TutorialsPreComposed Packages

            Kommentar

            Lädt...
            X