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

Hi,

I am working on my first CodeIgniter project - using 3.1 and liking it so far!

However I have come across an issue which has stumped me and I haven't found anything online about it.

I have a route:

Code:
$route['storage/item/(:any)'] = 'StorageController/item/$1';

which is handled in the StorageController by:

Code:
  public function item($uniqid)
  {
      $filename = APPPATH.'storedData\\'.$uniqid.'.xyz';
      $data['xyz'] = file_get_contents($filename);
      $this->load->view('storage/item',$data);
  }

and the view is simply:

Code:
<?php header('Content-Type: text/plain'); ?>
<?php echo($xyz); ?>

or in other words, just displays the plain text file contents for the $uniqid that is stored in a set location on the webserver.

That works fine in the browser with an internal url of (for example) http://www.domain.com/storage/item/57d952d0a09d0

Now, I have a database table that stores URL's which may be external or internal (i.e. in the above example form) for which I want to retrieve the data.
That I attempt with file_get_contents:


Code:
  public function load($id)
  {
      $data['title'] = 'XYZ Data Load';

      $record = $this->StorageModel->getId($id);

      if($record !== NULL)
      {
        $data['description'] = $record->description;
        $data['url'] = $record->url;
        $data['xyz'] = file_get_contents($data['url']); //problem line

        $this->load->view('templates/head', $data);
        $this->load->view('storage/current/load',$data);
        $this->load->view('templates/footer');
      }
      else
      {
        $data['id'] = $id;
        $this->load->view('templates/head', $data);
        $this->load->view('storage/current/loadFailed',$data);
        $this->load->view('templates/footer');
      }
  }

If the stored URL is external (i.e. not under www.domain.com) then the file_get_contents works fine.
But for an internal URL it causes a 404 error, despite it displaying when typed into the browser address bar.

Can anyone shed some light on what is going on?

Many thanks!
Reply


Messages In This Thread
file_get_contents causes a 404 error - by gordski68 - 09-15-2016, 05:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB