2

How can I use is_file with a path like: /folder/file.jpg please?

Thank you!

2 Answers 2

3

If the path starts with a / this means the path is absolute. When the path is relative (ie not starting with /) then the path relative to the php script is taken. If you want to have /folder/file.jpg relative to the server root, you can append the root.

$path = $_SERVER['DOCUMENT_ROOT'] . '/folder/file.jpg';
Sign up to request clarification or add additional context in comments.

Comments

1

Use $_SERVER['DOCUMENT_ROOT']:

$is_file = is_file($_SERVER['DOCUMENT_ROOT'] . '/folder/file.jpg');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.