Reputation: 754
I know that there are other questions similar to this, but I couldn't find the solution in it.
I am using absolute local pdf file and I want to use file_get_contents()
function. My code:
$fileName = 'C:/Users/my_user/Desktop/thisispdf.pdf';
$content = file_get_contents($fileName);
The thing is that it says that the file is not found. When I put it the filename into file explorer, the pdf opens up immediately. I also was trying to change the slashes from /
to \
and even use \\
, but none of these helped.
What I am missing here?
Upvotes: 2
Views: 1654
Reputation: 1488
On different OSs, your path needs to be changed. Windows uses back slash. Try this
C:\\Users\\my_user\\Desktop\\thisispdf.pdf
Difference between forward slash (/) and backslash (\) in file path
Upvotes: 0
Reputation: 1960
It's possible the web server doesn't have permissions to access that user's files. If you move the file to an accessible or shared location it may work. (You can also change permissions to permit access, however doing that on the user's personal directory is not advisable since it could expose other information to unauthorized users.)
Upvotes: 2