wood burning stoves 2.0*
The moose likes PHP and the fly likes Not able to create textFile in server using  php - urgent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Languages » PHP
Bookmark "Not able to create textFile in server using  php - urgent" Watch "Not able to create textFile in server using  php - urgent" New topic
Author

Not able to create textFile in server using php - urgent

Rakesh Kumar
Ranch Hand

Joined: May 30, 2006
Posts: 63
Dear friends,
I am doing a php project. I want to create a text file in server from client and writr some data init using php.I used following code.
But it is not able to create the file.

$myFile = "test.txt";
$fh = fopen($myFile, 'w') or die("can't open file...");
$stringData = "New Stuff 1\n";
fwrite($fh, $stringData);
$stringData = "New Stuff 2\n";
fwrite($fh, $stringData);
fclose($fh);


Please share your valuable ideas and thought abt this.It is little urgent.
Thanks
Rakesh
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 1966
    
    7

Hello Rakesh

What error did you get? The "die" message or you got the file created but nothing in it?


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7
Rakesh Kumar
Ranch Hand

Joined: May 30, 2006
Posts: 63
Dear T sang,

if i put die("") it shows die message but page is not at all created.

But I observed one thing that, if i create the file and chmodd 777 and fwrite() I call it will write it.

Thanks for your response.
rakesh
Rakesh Kumar
Ranch Hand

Joined: May 30, 2006
Posts: 63
T sand I hv to do it in apache server.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 1966
    
    7

It looks like to me that it's just a security setting. If you created the file first BUT don't change mode to 777, the file should be blank after the script runs. Also are you running apache as root or admin or just some plain user? I recall that the web directories' owner need to be the same user as the one who runs those script.

If nothing works add in chmod("777") or chmod("766") before the fopen statement and change back about writing the file.

Hope this helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to create textFile in server using php - urgent
 
Similar Threads
urgent
Writing to a web server
URGENT!!!
Urgent !
get value on click from table using javascript