[php]file_get_contents not recognizing file
I have this very simple code:
PHP Code:
<?php
if(!isset($_POST['submit'])) {
if(file_get_contents($index) == false) {
die("Failed to open index file.");
}
}
?>
Where $index contains "/pielite/index.htm" and it keeps giving me this error:
Warning: file_get_contents(/pielite/index.htm) [function.file-get-contents]: failed to open stream: No such file or directory in /customers/pie-designs.net/pie-designs.net/httpd.www/pielite/admin/content/scontent.php on line 4
Failed to open index file.
While it in fact does exist, I'm sure it's something really stupid but it's driving me crazy I can't get it too work.
Any suggestions?
Re: [php]file_get_contents not recognizing file
Will it work if you append '../../' before $index?
Re: [php]file_get_contents not recognizing file
If nothing works maybe you could fully type the url; http://url.ext/pielite/index.html ?
Re: [php]file_get_contents not recognizing file
Quote:
Originally Posted by
Daevius
Will it work if you append '../../' before $index?
Yes it does, but it isn't really pretty code. Also, I thought that a slash infront of the directory would mean that it looks for the directory in the main directory.
Quote:
Originally Posted by
EliteGM
That would probably work but why would I want to open a file through a http protocol when it's located on my own server?
Re: [php]file_get_contents not recognizing file
Ok, I figured out the problem. Apparently, file_get_contents in an if statement makes php cry.
Re: [php]file_get_contents not recognizing file
Quote:
Originally Posted by
Pieman
Ok, I figured out the problem. Apparently, file_get_contents in an if statement makes php cry.
Lol are you certain that the if statement isn't making PHP cry?
Re: [php]file_get_contents not recognizing file
Well yes, else it wouldn't give that error...
Re: [php]file_get_contents not recognizing file
It's not the if statement. You're providing an absolute path that doesn't exist.
Either provide the true absolute path, or append the current directory.
PHP Code:
$index = "./pielite/index.htm";