Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Not able to create textFile in server using php - urgent

 
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
 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser 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: 3648
16
Mac OS X Firefox Browser 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.
 
Do you want ants? Because that's how you get ants. And a tiny ads:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic