I am facing using in accessing files in Codeigniter. I will explain using examples. Suppose I have an Xampp folder in c drive and my project is running fine and I am trying to access D drive folder and that folder has some PDF so I have I access ??
<a target="_blank"
href="'.fopen('D:/pdf_file/demo.pdf', "r").'"><i class="fa fa-eye text-success" aria-hidden="true"></i></a>
Note – My project is in C drive
2
Answers
The
href
attribute on<a>
elements in HTML cannot execute PHP code such asfopen()
directly. The href attribute in HTML only functions to specify a URL or link that will be opened when the user clicks on it.To display a PDF file in the browser, you can use the
<a>
element with thehref
attribute pointing directly to the URL of the PDF file that can be accessed by the browser. For example:It’s important to note that URLs like
D:/pdf_file/demo.pdf
in the href attribute will not work properly because it is a local file path on your system.I suggest you to create a functional link, the PDF file needs to be hosted and accessed through a network-accessible URL, such as
https://www.example.com/demo.pdf
.And if you want to download the source you can just simply add
download
attribute to the<a>
tag as you can see below :In your code, you are using the fopen() function to open a PDF file located at D:/pdf_file/demo.pdf (especially for href of a tag).
The href attribute is used to specify the URL of the page or resource that the link points to.
If you want to access files outside of your CodeIgniter project directory, you need to use the correct absolute path to that directory in your code. You can use the realpath() function to get the absolute path of a directory or file on your server.
Hope this will help you!