Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file_put_contents fails to create file in the included path

Tags:

php

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);
like image 742
AL-zami Avatar asked Mar 17 '23 00:03

AL-zami


1 Answers

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.

like image 88
AbraCadaver Avatar answered Mar 20 '23 03:03

AbraCadaver