Search
 
SCRIPT & CODE EXAMPLE
 

PHP

download file php

1.  <?php
2.  $dir="download/";
3.  $filename=$_GET['file'];
4.  $file_path=$dir.$filename;
5.  $ctype="application/octet-stream";
6.  //
7.  if(!empty($file_path) && file_exists($file_path)){ //check keberadaan file
8.    header("Pragma:public");
9.    header("Expired:0");
10.   header("Cache-Control:must-revalidate");
11.   header("Content-Control:public");
12.   header("Content-Description: File Transfer");
13.   header("Content-Type: $ctype");
14.   header("Content-Disposition:attachment; filename="".basename($file_path).""");
15.   header("Content-Transfer-Encoding:binary");
16.   header("Content-Length:".filesize($file_path));
17.   flush();
18.   readfile($file_path);
19.   exit();
20. }else{
21.   echo "The File does not exist.";
22. }
23. ?>
Comment

file downloading in php

<?php
if(isset($_REQUEST["file"])){
// Get parameters
    $file = urldecode($_REQUEST["file"]); // Decode URL-encodedstring
    $filepath = "images/" . $file;

// Process download
    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: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($filepath));
        flush(); // Flush system output buffer
        readfile($filepath);
        exit;
    }
}
?>
Comment

How to Download a File in PHP

<?php
if(isset($_REQUEST["file"])){
    // Get parameters
    $file = urldecode($_REQUEST["file"]); // Decode URL-encoded string

    /* 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
        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: must-revalidate');
            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!");
    }
}
?>
Comment

PREVIOUS NEXT
Code Example
Php :: remove square brackets from string php 
Php :: -store() laravel change name 
Php :: SQLSTATE[42S02] lumen 
Php :: php get html tags from string 
Php :: $ is not define in laravel 
Php :: convert collection to array laravel 
Php :: laravel eloquent update multiple records 
Php :: set cookie on button click JavaScript 
Php :: yii 2 create migration with fields 
Php :: laravel pivot table model 
Php :: laravel validation exists array 
Php :: PHP Ternary Operator With Elseif Example 
Php :: php one line if without else 
Php :: encryption and decryption in php example 
Php :: laravel casts AsCollection 
Php :: spatie activity log 
Php :: Securing form from possible sql injection 
Php :: make controller and model laravel 
Php :: PHP temporary files 
Php :: how to use php 
Php :: how to check if a user is logged in in a non middleware controller in laravel 
Php :: timezones php 
Php :: wp php footer date automatically 
Php :: Eager realationship in laravel 
Php :: how to check ia folder if no have files in php 
Php :: laravel event listener 
Php :: empty func php 
Php :: err_cache_miss php 
Php :: php get referrer ajax 
Php :: delete all rows in table laravel foreign key 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =