2

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?

HELPME
  • 714
  • 14
  • 35
  • 5
    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. – IronMan Jul 08 '19 at 19:31
  • @IronMan thanks for your comment. You're right. After putting file into an accessible folder, it works. Please, put an answer instead of a comment and I will accept it. – HELPME Jul 08 '19 at 19:38
  • 1
    Yes, the Apache or IIS user won't have access to other users files in the Users directory. – AbraCadaver Jul 08 '19 at 19:38

2 Answers2

2

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.)

IronMan
  • 1,854
  • 10
  • 7
0

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

X 47 48 - IR
  • 1,250
  • 1
  • 15
  • 28