CodeIgniter Forums
ERR_FILE_NOT_FOUND error. I know the file exists - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: ERR_FILE_NOT_FOUND error. I know the file exists (/thread-60053.html)



ERR_FILE_NOT_FOUND error. I know the file exists - El Forum - 01-06-2014

[eluser]bazianm[/eluser]
I have something wierd going on and I cannot figure it out. Not even sure how to google this. I hope someone here can help.

Scenario (related to a prior post) is this:

File stored on disk with a UUID as the name. Renaming the file on download.

The user clicks on a link that is as constructed as follows:

Controller/method/file_name/FileURL/MimeType

File name - The name that the file WILL be (this is urlencoded)
FileURL - The URL to the file on disk - This is a UUID of the file and it is encrypted
The mime type of the file - This is urlencoded

The controller calls a view that constructs a header so the file is downloaded. Here's the view:

Code:
<?php

//Just something for debugging
$download = true;

$filename = urldecode($filename);

$header[0] = "Content-Length: " . filesize ($fileurl);
$header[1] = "Content-type: application/octet-stream";
$header[2] = "Content-disposition: attachment; filename=\"$filename\"";
$header[3] = 'Expires: 0';
$header[4] = 'Cache-Control: must-revalidate, post-check=0, pre-check=0';

foreach($header as $line){
if($download){
  header($line);
}else{
  echo $line . "<br>";
}
}

if($download){
ob_clean();
flush();
readfile($fileurl);
}else{
var_dump($filename,$fileurl);
}
?&gt;

Now, I know the controller is being called because, when I set $download to false, all the debugging information shows correctly.

I know the fileurl is found because I am getting the right file size.

Yet, when I run this with $download = true, I am getting an ERR_FILE_NOT_FOUND in chrome. In firefox, it tells me "Firefox can't find the file at" and then shows the URL.

Any ideas on this? I am stumped....