Jump to content


Photo

problem with specifying directory when using file_get_content()


  • Please log in to reply
2 replies to this topic

#1 hanhao

hanhao
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 29 May 2006 - 08:28 AM

problem with specifying directory when using file_get_content()

i got a problem with this function
sim.txt is the file that i wish to read. it is stored in website_root\color_scripts\sim.txt

this is my code

$simtxt_contents = file_get_contents("color_scripts\sim.txt");

here is the error message


Warning: file_get_contents(color_scripts\sim.txt) [function.file-get-contents]: failed to open stream: No such file or directory in C:\Program Files\xampp\htdocs\website_root\test_colorsim.php on line 21


the strange thing is i specified the directory as "color_scripts\sim.txt" , and NOT \test_colorsim.php\

is there anyway to solve this problem?
do i need to escape ta directory up?
using apache on my computer
please help

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 29 May 2006 - 08:38 AM

You might try escaping your backslash. eg;
file_get_contents("color_scripts\\sim.txt");


#3 hanhao

hanhao
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 29 May 2006 - 08:58 AM

thnx for reply!


i managed to solve my problem
here is the solution


$server_root = $_SERVER['DOCUMENT_ROOT'];
$simtxt_contents = file_get_contents("$server_root/website_root/color_scripts/sim.txt");




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users