file_put_contents fails to create file in the included path

Issue

I am trying to create a text file in the desktop.I created an included path using set_include_path() but the file is created in my xampp/htdocs folder.How can i create the folder in my desktop??Is it possible??

set_include_path(',;c:/users/shimantta/Desktop');

echo file_put_contents("/test.txt","Hello World. Testing!",FILE_USE_INCLUDE_PATH);

Solution

The include path is the path that PHP searches when you include/require a file, not when you write to a file.

include_path Specifies a list of directories where the require, include, fopen(),
file(), readfile() and file_get_contents() functions look for files.

Just give the complete path:

file_put_contents("c:/users/shimantta/Desktop/test.txt", "Hello World. Testing!");

This will only work if the user running the script or the user running the webserver has permission to write to that directory.

Answered By – AbraCadaver

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published