0

https://stackoverflow.com/a/10743881/1303216

I'm currently working off of this. I copy and pasted the code and have been tinkering to get it to work. On the webroot of my server there is a folder called secretfolder. In public_html there is a PHP file with the script to fetch my hidden PDF (copied code). The problem is, the files keep coming out corrupt and when I look at them in Notepad, I get

failed to open stream: No such file or directory in <b>/home/user/public_html/herp.php

How do I get it to point outside of public_html. I don't entirely understand relative file paths so some help would be great.

I'm on a standard LAMP

Short Question

What would the relative file path be from a PHP file in Public_html that needs to point to /secretfolder that is directly on the webroot?

Side note, I didn't just try $file = '/path/to/file/outside/www/secret.pdf'; but I need to know what that is supposed to be in actual use.

Update

The file path I was using was /secretfolder/Pay%20Stub%20View.pdf

%20 (Spaces) for some reason was breaking it. It works fine now. I feel kind of dumb. Can anyone explain why this happens? All I know is that it does.

Community
  • 1
  • 1
Will
  • 733
  • 8
  • 23

1 Answers1

1

Short answer

I do not know the layout of your file system. But PHP/Apache has access to the lot (assuming right file permissions). I tend to use relative paths as you can then easily transfer from development to production/testing environments without the hassle.

Longer answer

Is there a file /home/user/public_html/herp.php on the server?

To answer the other question, relative paths use the .. notation for directories. It means the sub-directory - the branch below. Just view the file system as a tree. The leaves are the files. The various branches are the directories. To reach the directory/branch holding up your current directory/branch - use the .. notation.

You can even get to the trunk if you so desire! Hope that helps.

Ed Heal
  • 59,252
  • 17
  • 87
  • 127