| 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
Ranch Hand
Joined: Sep 13, 2007
Posts: 1259
|
|
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
|
 |
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
Ranch Hand
Joined: Sep 13, 2007
Posts: 1259
|
|
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.
|
 |
 |
|
|
subject: Not able to create textFile in server using php - urgent
|
|
|