Welcome Guest, Not a member yet? Register   Sign In
file_get_contents - returning error No such file or Directory.
#1

[eluser]Unknown[/eluser]
Hi,

I am just starting up and exploring CI and have enjoyed it so far. Struggling with a few things and finding the forum excellent - great community.

I am having trouble with the following code to download a file from the server. I am confused about the resulting error that indicates the file does not exist.

Code:
function get_file()
    {
        
        $this->load->helper('url');
        $this->load->helper('download');
        //file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/public/downloads/test.zip');
        $path = $_SERVER['DOCUMENT_ROOT'] . '/public_files/islclient.exe';
        $data = file_get_contents($path); // Read the file's contents
        $name = 'islclient.exe';
        force_download($name,$data);

            // echo $_SERVER['DOCUMENT_ROOT'];  
        $this->load->view('remote_support_view');
    }

The error that is returning is as follows;

Severity: Warning

Message: file_get_contents(/home/domain.com/public_html/hub/public_files/islclient.exe) [function.file-get-contents]: failed to open stream: No such file or directory

Filename: controllers/remote_support.php

Line Number: 23
----------------

I read through the other posts and used the sample code but I think I am missing a point to do with the path relative to CI and how CI is interpreting the path.

thanks in advance for any "push" in the right direction.

David
#2

[eluser]coolfactor[/eluser]
Probably don't want to be using file_get_contents(), but rather readfile().

file_get_contents() returns the contents as a text string, but readfile() sends the data as-is to the output buffer.




Theme © iAndrew 2016 - Forum software by © MyBB