• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Not able to create textFile in server using php - urgent

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
T sand I hv to do it in apache server.
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic