HELPME
HELPME

Reputation: 754

file_get_content: failed to open stream: No such file or directory

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

Answers (2)

X 47 48 - IR
X 47 48 - IR

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

IronMan
IronMan

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

Related Questions