PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 1, 2022

[FIXED] PHP writing to file on server

 March 01, 2022     lamp, php     No comments   

Issue

I'm trying to write to a file on my local server and I can't figure out why, I haven't found any good reason why what I'm doing should not work.

What I've tryed:

file_put_contents("./lol.txt", "Contents");
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/lil.txt", "Contents");
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "lal.txt", "Contents");
file_put_contents("lel.txt", "Contents");

I will provide any additional info if needed.


Solution

Use realpath — Returns canonicalized absolute pathname

file_put_contents(realpath("somedirectory/somefile.txt"),$content);

and check the permission for folder and file whether you have write access.



Answered By - Aditya Shah
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing