Questions tagged [file-put-contents]

`file_put_contents()` is a PHP function which writes a string to a file.

file_put_contents() is a PHP function, introduced in PHP 5.1.0, which writes a string to a file. It was added as a shortcut and calling this function is identical to calling fopen(), fwrite(), and fclose() successively to write data to a file.

If the file attempting to be written to does not exist, the default behavior of the function is to create the file.

For more information on this function, please see the PHP manual: https://php.net/manual/en/function.file-put-contents.php

245 questions
2
votes
1 answer

How add php array with file_put_contents ? - PHP

i want to add/create a php file with inside an array using file_put_contents(). $arr= array('red'); $content= ""; file_put_contents('file.php', $content); But then if i open file.php i read this:
Borja
  • 3,359
  • 7
  • 33
  • 66
2
votes
3 answers

php file_put_contents no such file or directory occasionally

I start 8 processes to execute a job, the code in the job like this:
wlstony
  • 43
  • 1
  • 8
2
votes
1 answer

WordPress: wp_filesystem->put_contents only writes last call

I have a WordPress issue and want to simply write log messages to a text file. I am aware that error_log exists, but want to have a more segregated log file for different messages. I am using wp_filesystem->put_contents, and it DOES write to the…
Richard Duerr
  • 566
  • 8
  • 24
2
votes
1 answer

Can PHP save to a file during __destruct()

I would like to save some info to a file on my server using the __destruct() function in one of my classes. However, every time I try to use file_put_contents(...) inside __destruct(), I get this error: Warning: file_put_contents(HTMLcache.txt):…
Hoytman
  • 1,722
  • 2
  • 17
  • 29
2
votes
0 answers

Is it safe to save search data to a text file?

I am saving search data on website to text file on my disk. I want to know if it is safe to do that. What if some virus script is saved into the file? is it harmful? This is the code that I am using to save form data to text file: if(isset($_GET…
Vinay
  • 2,272
  • 4
  • 19
  • 34
2
votes
0 answers

PHP Decode Base64 Image to png and save in current directory

I know there are so many solutions for decode base64 image. But any of them didn't work for me. I have the Base64 image data and i need to convert it to a png file and save it to the local directory. I tried the following code which i got from…
2
votes
3 answers

file_get_contents, failed to open stream: Redirection limit reached

My codes is : if ( isset($_POST['gd_url']) && isset($_POST['accessToken'])) { $url = "https://drive.google.com/uc?export=download&id=".$fileId; // $url = $_POST['gd_url']; $name = $_POST['file']; $accessToken =…
Alphadha
  • 23
  • 4
2
votes
1 answer

Correct permissions for directory to execute file_put_contents()

I am working on a website where I allow users to upload an image to a server. In order for file_put_contents() to get the correct permissions, I had to change the user on the server to www-data (the current user for the Apache server). I am just…
Tyler Pashigian
  • 457
  • 4
  • 13
2
votes
2 answers

Get Image With file_get_contents it return Not Found Error

I have one Image on another server (Image).but when i get this image With file_get_contents() function it will return Not Found Error and generate this Image. file_put_contents(destination_path, file_get_contents(another_server_path)); plz help…
Bhavik Hirani
  • 1,996
  • 4
  • 28
  • 46
2
votes
2 answers

How do I put content on second line in .txt file and read it

For storing values in a .txt file I use this code: file_put_contents('data/vote_result.txt', implode(',', $results)); and for reading i use this: $results = explode(',', file_get_contents('data/vote_result.txt')); The content of vote_result.txt…
Jack Maessen
  • 1,780
  • 4
  • 19
  • 51
2
votes
1 answer

convert file_put_contents to curl

I have a function to create cache data xml file on my server. I've used file_get_contents and file_put_contents, but now my hosting provider is restricting usage of them. The single way to use same function is to convert it to CURL. Can anyone give…
2
votes
1 answer

PHP creates two files at a time with different files names but with the same content

The goal is to create a repository of a custom session files. When I use this code to write data to a session file, php creates two files with different names but with the same content. Why is this happening? $uniqFileName = sha1(uniqid('', true)) .…
2
votes
1 answer

file_put_contents not working

I try to upload something to my ubuntu server by file_put_contents (a converted base64-string as .jpg) with the following code : file_put_contents($filename, base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data))); And yes, all…
nameless
  • 1,483
  • 5
  • 32
  • 78
2
votes
2 answers

file_put_contents() expects parameter 1 to be a valid path, string given

I have the following simple script (stripped down): define("LANG_DIR", "../../app/lang/"); // define("LANG_DIR", "/var/www/html/app/lang/"); // ############# // Some parsing of an CSV file, from with we will create .php files //…
Mathlight
  • 6,436
  • 17
  • 62
  • 107
1
2
3
16 17