How do I generalise or neutralise the difference between base_url()
and getcwd()
?
In a view, I want to display both an inline PDF-viewer (using the <object src=''></object>
) and the OCR'ed output. Both of these require the same source file, which is located in project/public/corpus/<some_id>/file.pdf
(where project
is the CodeIgniter root).
The code in the controller can be summarised like this:
/**
* Fetch the path to the pdf of the document (OCR is preferred)
* $handle is a unique identifier
*/
$object_src = base_url("public/mi-corpus/" . $handle . "/file.pdf");
$ocr_src = getcwd()."/public/mi-corpus/" . $handle . "/file.pdf";
// Returns an <object> node from the source
$this->data['object'] = $this->get_pdf($ocr_src);
// uses a cloud OCR to parse the source and return OCR'ed text, this is irrelevant. But it does use file_exists($src) to check if the path is valid.
$this->data['ocr'] = $this->mipreprocessing->open_ocr($ocr_src);
The thing is, when using base_url()
, the function file_exists($src)
always fails, but the getcwd()
concatenation fails when producing a src
attribute for the HTML <object>
.
I see that base_url()
yields a 'real' URL-like string ("http://localhost/" etc.), whereas getcwd()
yields the actual path on the machine ("D:\wamp\www" etc. in my case, using WAMP on Windows 10, I know, it's not ideal).
Is there any way to generalise this statement so that I don't need two separate paths concatenations? Am I doing this all wrong?