MasterT
MasterT

Reputation: 623

PHP to get File content of dynamic generated file

I want to collect the content of a dynamically generated file, and place the content inside an email that will be sent but am unable to return the content.

/file/invoice/html/{id}

The file its self is a .htaccess written file so it is not actually the location or the file its self, i want the content that the you see when viewing in the browser I want to be able to get the contents of it and insert it into an email as content.

The .htaccess controls the type of file and format of the file. the htaccess that i am using for the file is

RewriteRule ^file/([^/]+)?$ file.php?file=$1 [QSA]  
RewriteRule ^file/([^/]+)/([^/]+)?$ file.php?file=$1&find=$2 [QSA]  
RewriteRule ^file/([^/]+)/([^/]+)/([^/]+)?$ file.php?file=$1&type=$2&find=$3 [QSA]  

I have tried

file_get_contents('http://domain.com/file/invoice/html/1')
file_get_contents('./file/invoice/html/1')

but this does not bring back the content that I can see. i have worked out that it is the "is user logged in check" that is stopping it but as u can guess i dont want to remove this from the file. is there a way to do this with it still there . this is the bit stopping it but i would prefer not to remove it

if (!isset($_SESSION['LOGGED_IN'])){
    die(CLOSE_WINDOW);
}elseif(isset($_SESSION['LOGGED_IN']) && $_SESSION['LOGGED_IN'] != TRUE){
    die(CLOSE_WINDOW);
}

What I am doing wrong and how can I solve it?

Upvotes: 1

Views: 765

Answers (1)

Matt Borja
Matt Borja

Reputation: 1587

You're attempting to download a remote file using file_get_contents. This is essentially the same question here: https://stackoverflow.com/a/3488430/901156.

If you truly want to be able to do this, you have to update your PHP config to allow_url_fopen

Also, it has been suggested [for security and other reasons] to use cURL instead.

Upvotes: 2

Related Questions