Welcome Guest, Not a member yet? Register   Sign In
file_get_contents causes a 404 error
#4

Here's a way to check the return of file_get_contents and, at the same time, make the function a lot more DRY.

Code:
public function load($id)
{
    $data['title'] = 'XYZ Data Load';
    $this->load->view('templates/head', $data);

    $data['id'] = $id;
    $view = 'storage/current/loadFailed';

    $record = $this->StorageModel->getId($id);
    if($record !== NULL)
    {
        $file = file_get_contents($record->url); //problem line
        if($file !== FALSE)
        {
            $data['description'] = $record->description;
            $data['url'] = $record->url;
            $data['xyz'] = $file;
            $view = 'storage/current/load';
        }
        else //else for development debug only. Remove it once you figure out what's going on
        {
            print_r(error_get_last());
        }
    }

    $this->load->view($view, $data)->view('templates/footer');
}
Reply


Messages In This Thread
RE: file_get_contents causes a 404 error - by dave friend - 09-15-2016, 07:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB