download in php

 https://www.php.net/manual/en/function.readfile.php

https://www.phptutorial.net/php-tutorial/php-download-file/

<?php

if(isset($_REQUEST["q"])){
    // Get parameters
    $filepath = urldecode($_REQUEST["q"]); // Decode URL-encoded string
//echo $filepath;

/* Check if the file name includes illegal characters
    like "../" using the regular expression */
    // if(preg_match('/^[^.][-a-z0-9_.]+[a-z]$/i', $file)){
    //     $filepath = "images/" . $file;

        // Process download
       echo basename($filepath);
    }
       /* if(file_exists($filepath)) {
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename="'.basename($filepath).'"');
            header('Expires: 0');
            header('Cache-Control: public');
            header('Pragma: public');
            header('Content-Length: ' . filesize($filepath));
            flush(); // Flush system output buffer
            readfile($filepath);
            die();
        } else {
            http_response_code(404);
            die();
        }
    } else {
        die("Invalid file name!");
    }*/
//}
?>

Comments

Popular posts from this blog

interview questions js[ Anurag Singh ProCodrr]

reactnative_creation