Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to download file using PHP script

    • 0
    • 3
    • 3
    • 1
    • 0
    • 0
    • 0
    • 0
    • 430
    Comment on it

    We use this script to download a file from a given define file path location

    In this script we are using two variable:

    1:) $fileName // for file name with path.
    2:)$title //for file name changed in you given title name.

    <?php
       $fileName = "images/image.jpg"; // define static file name with location;
       $title = "image-new";
    
        header("Pragma: public");
        header('Content-disposition: attachment; filename='.$title);
        header("Content-type: ".mime&#95;content&#95;type($fileName));
        header("Content-Length: " . filesize($fileName) ."; ");
        header('Content-Transfer-Encoding: binary');
        ob&#95;clean();
        flush();
    
        $chunksize = 1 * (1024 * 1024); // how many bytes per chunk
        if (filesize($fileName) > $chunksize) {
            $handle = fopen($fileName, 'rb');
            $buffer = '';
    
            while (!feof($handle)) {
                $buffer = fread($handle, $chunksize);
                echo $buffer;
                ob&#95;flush();
                flush();
            }
    
            fclose($handle);
        } else {
            readfile($fileName);
        }
    ?>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: