1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Not show file size when download by this script

Discussion in 'PHP' started by Tuhin1234, Oct 3, 2018.

  1. #1
    This script limit download but problem when download not show the file size.Anyone please help me.


    <?php
    // Set the maximum number of downloads (actually, the number of page loads)
    $maxdownloads = "5";
    // Set the key's viable duration in seconds (86400 seconds = 24 hours)
    $maxtime = "3600";
    
    require ('dbconnect.php');
    
        if(get_magic_quotes_gpc()) {
            $id = stripslashes($_GET['id']);
        }else{
            $id = $_GET['id'];
        }
    
        // Get the key, timestamp, and number of downloads from the database
        $query = sprintf("SELECT * FROM downloadkey WHERE uniqueid= '%s'",
        mysql_real_escape_string($id, $link));
        $result = mysql_query($query) or die(mysql_error());
        $row = mysql_fetch_array($result);
        if (!$row) {
            echo "The download key you are using is invalid.";
        }else{
            $timecheck = date('U') - $row['timestamp'];
           
            if ($timecheck >= $maxtime) {
                echo "This key has expired (exceeded time allotted).<br />";
            }else{
                $downloads = $row['downloads'];
                $downloads += 1;
                if ($downloads > $maxdownloads) {
                    echo "This key has expired (exceeded allowed downloads).<br />";
                }else{
                    $sql = sprintf("UPDATE downloadkey SET downloads = '".$downloads."' WHERE uniqueid= '%s'",
        mysql_real_escape_string($id, $link));
                    $incrementdownloads = mysql_query($sql) or die(mysql_error());
                   
    // Debug        echo "Key validated.";
    
    // Force the browser to start the download automatically
    
    /*
        Variables:
            $file = real name of actual download file on the server
            $filename = new name of local download file - this is what the visitor's file will actually be called when he/she saves it
    */
    
       ob_start();
       $mm_type="application/octet-stream";
       $file = "http://mysite.com/kgbkigh/".$_GET['ids'].".mp4";
       $filename = "mysite-".$_GET['ids']."(mysite.com).mp4";
       header("Cache-Control: public, must-revalidate");
       header("Pragma: no-cache");
       header("Content-Type: " . $mm_type);
       header("Content-Length: " .(string)(filesize($file)) );
       header('Content-Disposition: attachment; filename="'.$filename.'"');
       header("Content-Transfer-Encoding: binary\n");
       ob_end_clean();
       readfile($file);
    
                }
            }
        }
    ?>
    PHP:

    SEMrush
     
    Tuhin1234, Oct 3, 2018 IP
    SEMrush
  2. hdewantara

    hdewantara Active Member

    Messages:
    442
    Likes Received:
    37
    Best Answers:
    19
    Trophy Points:
    80
    #2
    You mean to show file size after download?

    To show it on page where the originating form resides, I could think of saving that
    filesize($file)
    Code (markup):
    into a session var then retrieve it with an ajax, right after submission.
     
    Last edited: Oct 3, 2018
    hdewantara, Oct 3, 2018 IP
  3. SaleSmith

    SaleSmith Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    If you want to deliver a large file, you need to send this file in parts. Search google "php streaming big files".
     
    SaleSmith, Oct 4, 2018 IP