Search code snippets, questions, articles...

Download file from remote url to user desktop in PHP

<?php
    $file_url = $_GET['file_url'];
    $file_name = basename($file_url);
    header('Content-Type: application/octet-stream');
    header("Content-Transfer-Encoding: Binary");
    header("Content-disposition: attachment; filename=\"".$file_name."\"");
    readfile($file_url);
    exit;
?>
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

To download a file on a user desktop from a remote URL in PHP, you can use this code snippet. We are using readfile() PHP function for that and also Content-disposition header which is required to download the file.

Search Index Data (The code snippet can also be found with below search text)

Save file from url to user system PHP
Was this helpful?
0 Comments