CodeIgniter Forums
file_get_contents - returning error No such file or Directory. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: file_get_contents - returning error No such file or Directory. (/showthread.php?tid=3249)



file_get_contents - returning error No such file or Directory. - El Forum - 09-19-2007

[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


file_get_contents - returning error No such file or Directory. - El Forum - 09-19-2007

[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.