Jump to content


Photo

Seems like a simple problem, but frustrating nonetheless...


  • Please log in to reply
6 replies to this topic

#1 xenmaster

xenmaster
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 26 October 2006 - 02:54 AM

Hi all,

I'm new to Php, and I love it, despite my problem. I'm trying to add a script into a default Wordpress install on my local server. I'm basically trying to load a text file into a variable and then use it. When I load the page I get the following error:

Warning: file(page.txt) [function.file]: failed to open stream: No such file or directory in C:\xampp\htdocs\wp-content\themes\classic\index.php on line 11

Warning: join() [function.join]: Bad arguments. in C:\xampp\htdocs\wp-content\themes\classic\index.php on line 11


This is the beginning of the script:

<?php

$content_file = "page.txt";


And this is line 11:

$words = split(" ", join("", file($content_file)));


From what I've read, it seems the text file simply isn't in the correct location, or that I may have capitalised incorrectly, etc. However, I have tried every permutation of localhost address (e.g $content_file = "http://localhost/page.txt";) and drive location ($content_file = "C:\xampp\htdocs\page.txt";) and nothing seems to work. What am I missing?

Thanks in advance for your help.


Gavin.

#2 Design

Design
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts
  • LocationThe Computer Chair

Posted 26 October 2006 - 02:58 AM

you only want to open the file?
in that case, fopen('page.txt',r); will open it in read-only format

#3 xenmaster

xenmaster
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 26 October 2006 - 03:05 AM

Hi,

Thanks for the quick reply.

I added the code so that it looks like this:

<?php

fopen('page.txt',r);

$content_file = "page.txt";



It results in this additional error:

Warning: fopen(page.txt) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\wp-content\themes\classic\index.php on line 6

Do I have to state the path to the file?

G.

#4 fert

fert
  • Members
  • PipPipPip
  • Advanced Member
  • 1,114 posts

Posted 26 October 2006 - 03:19 AM

try
$file=@fopen("page.txt","r") or die("Cannot find file");
$text=@fread($file,filesize("page.txt")) or die("Cannot read file");


Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2

#5 xenmaster

xenmaster
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 26 October 2006 - 03:26 AM

Hi,

Very clever, it has diagnosed the problem, I get:

'Cannot find file'

Where should I place the file?

#6 fert

fert
  • Members
  • PipPipPip
  • Advanced Member
  • 1,114 posts

Posted 26 October 2006 - 03:30 AM

it should be in the same folder as the script

Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2

#7 xenmaster

xenmaster
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 26 October 2006 - 03:34 AM

Yep, that's where I have it. I have put this new script at the top of the index.php in the following theme folder:
C:\xampp\htdocs\wp-content\themes\classic. Page.txt is in this directory too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users