Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to create textFile in server using php - urgent

 
Rakesh Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3444
13
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Rakesh

What error did you get? The "die" message or you got the file created but nothing in it?
 
Rakesh Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
T sand I hv to do it in apache server.
 
K. Tsang
Bartender
Posts: 3444
13
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic