Jump to content

Error Writing/reading Files


Nate
 Share

Recommended Posts

I've done all the debugging I could possibly do... I have a little chat script written in PHP that I've been playing around with.

 

It works fine on my WinXP box, and on my Linux box, but I've tried it on two different web hosts including my account with TCH and I always get erros when the script tries to read or write to it's files. I could tweak it to use a database, but that would make it harder just to drop into a folder and have it work.

 

The files are called 'chat.dat' to track what people are saying and 'active.dat' to track the talkative users.

 

If I use fopen($chatfile, "a+"); it'll open the chat.dat file bu~t...it won't read or write anything to it... When I use the same thing on the active.dat file it only writes one user to the file...no more...no less...one is the number that it writes... :P

 

I'm very confused...any questions or answers? :blink:

Link to comment
Share on other sites

If I use fopen($chatfile, "a+"); it'll open the chat.dat file bu~t...it won't read or write anything to it...  When I use the same thing on the active.dat file it only writes one user to the file...no more...no less...one is the number that it writes...  :P

My initial impression, this sounds to me like its a logic error somewhere in the program. If you can actually write to the file, that has already eliminated any issues you might be having with the system outside of the script.

 

I'd be happy to take a quick look through the script and see if anything jumps out at me if you'd like. I can't promise I'll be able to find the time to do it anytime in the next week or so, but I'll try. :blink:

Link to comment
Share on other sites

If I use fopen($chatfile, "a+"); it'll open the chat.dat file bu~t...it won't read or write anything to it...  When I use the same thing on the active.dat file it only writes one user to the file...no more...no less...one is the number that it writes...   :P

My initial impression, this sounds to me like its a logic error somewhere in the program. If you can actually write to the file, that has already eliminated any issues you might be having with the system outside of the script.

 

I'd be happy to take a quick look through the script and see if anything jumps out at me if you'd like. I can't promise I'll be able to find the time to do it anytime in the next week or so, but I'll try. :blink:

Well, it has to be a logic error in the code. Otherwise all the other scripts that write/read files on TCH servers would have the same issues. It just puzzles me that the script works fine on my own boxes... One an WinXP machine running Apache2 and PHP 4.3.1, and the other Slackware 9 running Apache 1.3 with PHP 4.3.1...

 

NEway, I'll keep poking at it. But I may take you up on the offer to look at it if I get too frustrated... :D

 

Nate

Link to comment
Share on other sites

Yay! Okay, here's the deal. When you open a file in 'a+' mode the file pointer is set to the end of the file, so when I tried to read back from the files I was opening I was ramming my script into a brick wall (past the end of the file). So, I called 'rewind($fp)' before both read operations and it's working now. :blink:

 

Don't ask me why it functions correctly under Slack and Win though...because now that I think about it, it shouldn't at all.... :P

 

Nate

Link to comment
Share on other sites

  • 6 months later...

How do you specify the actual file name? I'm trying to use a simple counter file, and have had no success opening the file with:

 

$fp = fopen( $counterFile, "r+" ) or die( "Can't open counter file [$counterFile]" );

 

It fails everytime. I know the file exists, although I can't seem to change the permissions from 644, but that's another issue.

 

I've also tried "r", "w", "a", and "a+" options with the exact same result. Do I have to give the full path? I've tried just "counter.txt", "www.ebackbid.com/counter.txt", "/home/ebackbid/public_html/counter.txt" and "public/counter.txt". I'm running out of permutations (and patience).

 

Thanks,

Dorsey

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...