logo
down
shadow

Force download in CodeIgniter


Force download in CodeIgniter

By : MrJorge2306
Date : November 18 2020, 03:01 PM
it fixes the issue You are passing null to the filename parameter, you need to pass it to the data parameter (2nd parameter), so your code should be like this
code :
public function download($id,$file_name)
{
    $this->load->helper('download');
    force_download(FCPATH.'/uploads/files/'.$file_name, null);
}


Share : facebook icon twitter icon
CodeIgniter force csv file download

CodeIgniter force csv file download


By : Sanjay
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You should try $data = file_get_contents("./reports/$filename.csv"); instead ;)
Codeigniter Force download files

Codeigniter Force download files


By : Jim
Date : March 29 2020, 07:55 AM
this will help I've had similar problems. I think the problem resides in certain mime's and headers sent to the browser(s). I've end up using the code I found here http://taggedzi.com/articles/display/forcing-downloads-through-codeigniter. Use the function below instead of force_download. It has worked for me so far.
code :
    function _push_file($path, $name)
    {
      // make sure it's a file before doing anything!
      if(is_file($path))
      {
        // required for IE
        if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); }

        // get the file mime type using the file extension
        $this->load->helper('file');

        $mime = get_mime_by_extension($path);

        // Build the headers to push out the file properly.
        header('Pragma: public');     // required
        header('Expires: 0');         // no cache
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($path)).' GMT');
        header('Cache-Control: private',false);
        header('Content-Type: '.$mime);  // Add the mime type from Code igniter.
        header('Content-Disposition: attachment; filename="'.basename($name).'"');  // Add the file name
        header('Content-Transfer-Encoding: binary');
        header('Content-Length: '.filesize($path)); // provide file size
        header('Connection: close');
        readfile($path); // push it out
        exit();
    }
}
Codeigniter, force download returns data not download panel

Codeigniter, force download returns data not download panel


By : Sagar Tiwarekar
Date : March 29 2020, 07:55 AM
will be helpful for those in need Use this method and arrange it as per your requirements. i have used it many times and it worked for me all the time
code :
//get records from database
$query = $db->query("SELECT * FROM list_item ORDER BY id DESC");

if($query->num_rows > 0){
    $delimiter = ",";
    $filename = "file_name_" . date('Y-m-d') . ".csv";

    //create a file pointer
    $f = fopen('php://memory', 'w');

    //set column headers
    $fields = array('ID', 'Name', 'Email', 'Phone', 'Created', 'Status');
    fputcsv($f, $fields, $delimiter);

    //output each row of the data, format line as csv and write to file pointer
    while($row = $query->fetch_assoc()){
        $status = ($row['status'] == '1')?'Active':'Inactive';
        $lineData = array($row['id'], $row['name'], $row['email'], $row['phone'], $row['created'], $status);
        fputcsv($f, $lineData, $delimiter);
    }

    //move back to beginning of file
    fseek($f, 0);

    //set headers to download file rather than displayed
    header('Content-Type: text/csv');
    header('Content-Disposition: attachment; filename="' . $filename . '";');

    //output all remaining data on a file pointer
    fpassthru($f);
}
How to force download zip file in codeigniter

How to force download zip file in codeigniter


By : Nathaniel
Date : March 29 2020, 07:55 AM
I wish this helpful for you I am trying to create a simple digital store web application using codeigniter. I would like to use the force download helper function so that the real url of the file will not be known by the user. I tried following the documentation in the codeignter - it works but the file get corrupted. , Use below function to download the file
code :
function auto_download($path, $name) {
  if(is_file($path))  {
    if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); }

    $this->load->helper('file');

    $mime = get_mime_by_extension($path);

    header('Pragma: public');
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($path)).' GMT');
    header('Cache-Control: private',false);
    header('Content-Type: '.$mime);
    header('Content-Disposition: attachment; filename="'.basename($name).'"'); 
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: '.filesize($path));
    header('Connection: close');
    readfile($path);
    exit();
}
Codeigniter Force download IE

Codeigniter Force download IE


By : tarik gete
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Frankly I am not sure why we bothered with a helper for downloads in code igniter.
It's not entirely hard to do in pure php:
Related Posts Related Posts :
  • How to add new Custom Title in Woocommerce My Account sidebar?
  • Mattermost, slash command response as message attachment
  • Library failure when installing Libsodium (Amazon EC2)
  • Page footer centering using MPDF
  • HTML : Different link at each click
  • TCPDF how to prevent page break within a block (split content)?
  • How to insert values in table
  • Php query builder for OR and AND condition
  • ZF2 Ajax call returns all information instead of just the id being sent
  • Order custom post types in WordPress by the meta_value of another plugin
  • saving bank row using array
  • Convert URL with query parameters to guzzle
  • Get POST values by index in codeigniter
  • Composer is not functioning?
  • Retrieving an Array with Axios in Laravel
  • How to get the last child of each cd element?
  • How to allow users to connect their own domain
  • PHP multidimensionnal array and empty value
  • PHP if statement doesn't work properly (paradoxical)
  • BadMethodCallException Call to undefined method Illuminate\Database\Query\Builder::searchable()
  • PHP explode() returns array inside an array
  • Echo parse error for creating new php file
  • PHP Parse error: syntax error, unexpected '?'
  • PHP Session not working correctly on a particular host
  • laravel how to get the extremities tables through the pivot
  • Show duplicate value in array only one but show all others
  • SMTP Emails not send (There is something wrong with server config as code is fine for other servers)
  • I can't turn off debug bar in Laravel on production
  • PHP creating multidimensional json
  • Increment value with get
  • Laravel 5.5: Convert query builder to eloquent
  • Reverse proxy onto a WordPress page?
  • Jumble Solver url rewrite
  • Using .htaccess to Execute php if directory of the same name not found
  • mysql - Unknown Column In Where Clause
  • Receive Emails into my Admin panel with php or other
  • PHP - adding only distinct value to an array in foreach loop not working
  • How to pass date picker from one page to another
  • Try catch always return error when I insert 2 data
  • Php redirect not working on submission
  • How to get array value from wordpress database get_results
  • how Automatically go from first.php to second.php
  • uploading file not working in codeigniter 3 error: you did not select any file
  • Yii2, gridview can not show some html tags inside cells
  • What are the thing we need to configure to implement live notification module (using redis and socket.io) in https serve
  • How to handle multi criterias search in PHP
  • PHP - Get maximum key and its value in array
  • PHP: how to retrieve all the metrics and dimensions from the Google Metadata API?
  • Deliver php mails to special-character-email adresses, such as äüö
  • Delete a single row from an MSSQL table from PHP
  • Property [name] does not exist on this collection instance
  • Pass input value through PHP parameter
  • Running two PHP versions on the same server (STRETCH)
  • Checking if a file has been selected for upload
  • Model not updating laravel
  • How to add a description of words from text to an array, to an array key by passing words?
  • Nginx rewrite rule not not passing variables if "/" is at the end of the url
  • Modify decimal point and thousands separator without changing the number of decimals
  • Remove PHP errors from CLI and PHPMyAdmin
  • Yii2 rest api - Url manager add parameters
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org