Problem with creating a file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Problem with creating a file

Post by pickle »

Hi All,

I'm having a little problem with creating a file and writing to it. I'm getting the error on this line:

Code: Select all

$file_handle = fopen("/path/to/the/file/to/create/$curr_date_$_POST[surname]_$_POST[first_name].txt",'w+');
The error I'm getting is;
PHP wrote: Warning: fopen(/path/to/the/file/to/create/1_2.txt) [function.fopen]: failed to create stream: No such file or directory in /path/to/file/doing/the/creation/file.inc on line 167
Line 167 is the code shown above.

I know the file name is correct, or at least valid, and I'm pretty sure about permissions, though this doesn't look like an error related to permissions.

I've tried using 'w','w+','a','wb' (not sure what wb is, though it was in the docs), but to no avail. Any ideas?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Are you trying to create a file in non-existing directory?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the b in wb is for binary.. just like wt is for text.

"/path/to/the/file/to/create/1_2.txt" differs from what should come from "/path/to/the/file/to/create/$curr_date_$_POST[surname]_$_POST[first_name].txt".. there should be atleast 2 underscores in the filename...
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Words cannot express how stupid I feel. Thanks.

~feyd - ya I know that's messed up. A separate issue though. Thanks.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply