There is a chance this is a bug, but I am pretty sure I must be overlooking something.
Basically JUri::base()
is removing the subdomain path, this is in siteground with its Joomla staging enviroments, so the domain it should be getting is http://staging1.domain.com
but instead it gets http://domain.com
.
I tested JUri::base()
in the template file, and it worked correctly, but in the custom component built for the site it does not.
Here is how it is being used:
$tmpFileName = md5($id.$Itemid.time()).'.pdf';
file_put_contents(
JPATH_SITE.'/tmp/'.$tmpFileName,
file_get_contents(
JUri::base()
.'index.php?option=com_component&view=finish&format=pdf&tmpl=component&data='
.$id
.'&Itemid='
.$Itemid
)
);
What the above code does is opens a generated pdf file (a pdf view) saves it to the tmp directory, then later in the script includes it as an attachment (deleting it afterwords).
If in this area i add JUri::base()
to the email (so I can see what it is according to the email sent) it strips the subdomain, I have confirmed that the redirection to the controller that does this function is correct, but the reason the url comes out improper in only this function eludes me (JRoute
works fine).
I cannot use JUri::base(true)
as it is the server attempting to get the contents of the file, so without the url it cannot get the file correctly. Also I have checked for the $live_site
variable in the configuration.php file and confirmed it is not a factor in this.
Most likely its something stupid I am overlooking, most likely right in front of my face and I will update the question with any findings as I go. So is there there anything that could cause this? Or has anyone ran into something similar?
Version is 3.3.1
UPDATE:
Dived deeper and here are my findings.
- I was wrong on thinking it was
JUri::base()
completely, although I had seen that it was getting the wrong variable now I see no evidence of it, although the result is the same, it is getting information from the live site and not the staging site. - I tested the execution of all the code and check the pdf generated when I go directly to the url that it generates, it creates the PDF perfectly, yet when done with the
file_get_contents
function it does something totally and completely different (grabs a pdf from the wrong url, even though the url seems to be correct and testing it worked). - I noticed I used an htpasswd on the site, and since the
file_get_contents
function goes to the url from the server itself it needs to authenticate, so there was no way a pdf should of been generated in this staging enviroment in the first place. This confirms that the pdf is being generated from the live site that has no htpasswd.