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
0
votes
1 answer

file_put_contents() effecting fileatime() of other files in directory

I've encountered a really strange bug I've been trying to resolve for the past few days unsuccessfully. I have a class for caching API calls, and a class used in a WordPress plugin to create custom API endpoints. In a nutshull the WordPress plugin…
nathansh
  • 81
  • 1
  • 10
0
votes
1 answer

Is it possible to write data in .zip file

According to this example:
user3629541
0
votes
2 answers

file_put_contents overwrites data

I use file_put_content to write data in file every time there is an entry in database. Instead of appending new entry it overwrites old data with new.Here is part of code which I am using.I tried with APPEND In flag but doesn't work. ` …
soni8010
  • 385
  • 1
  • 6
  • 19
0
votes
3 answers

Saving image file name exactly as URL image file into folder in PHP

I have visited this article previously and found it useful, but i would like to add more functionality to it by having it save an image file name according to the URL name. This is what I've done so far and it…
Jeiman
  • 1,121
  • 9
  • 27
  • 50
0
votes
1 answer

base64_decode image or pdf is failing in PHP when size is higher than 500kb

I'm uploading files (image or pdf) using AJAX. My process is converting the file to base64 then send the data via AJAX then process in server side (PHP) to become a image or pdf. This is my code in server side and it's working fine but failing when…
0
votes
1 answer

PHP print array in other pages for use over multiple pages

I need an array in multiple pages, so I tried to make a php file where the array is printed. I used: file_put_contents('file.php', ''); I was hoping that if I included this file in the files…
BenBen
  • 15
  • 2
0
votes
3 answers

Directly save image generated with php

Im generating Identicons using a php script. Showing the result using a works fine $input="create_image/identicon.php?size=48&hash=$hashvalue"; $output=$username."_userimage.png"; This works: echo ""; But this doesn't: (It…
Minzkraut
  • 2,149
  • 25
  • 31
0
votes
2 answers

file_put_contents and a new line and space

After sending the string via the email i want to save it into file. so i do it this way: file_put_contents("coupon.txt", $email. $RandomString , FILE_APPEND | LOCK_EX); and in this way it's look like…
praiA Tent
  • 17
  • 4
0
votes
0 answers

file_put_contents append executes successfully but the file is not appended

I am trying to log Parsing errors to a log file. Here's the snippet of code that is used to write to the log file. if(!array_key_exists(1,$match)) { $result = file_put_contents("$mapdir/$log_fname","\n$link",FILE_APPEND | LOCK_EX); …
Akshay Kalghatgi
  • 423
  • 1
  • 4
  • 11
0
votes
1 answer

How to create a file from very long content-length

I'm having a problem with writing a new image file from image-data (dataurl). Images lower than 1 mb is no problem with file_put_contents. But if the file is bigger than 1 mb. The function does not work. Procedure A DataUrl was sent to print.php…
Wilf
  • 2,297
  • 5
  • 38
  • 82
0
votes
2 answers

My PHP foreach loop outputs print_r correctly but not file_put_contents

I am using simple_html_dom to parse a page and return some content. When I try to output the content with print_r in the foreach loop, it returns all elements. However, if I try to output the contents to a text file, it only outputs the last…
Mike
  • 607
  • 8
  • 30
0
votes
1 answer

PHP Write To A file Overwriting Only Selected Sections

I am trying to dynamically write to a css file. The file already has some content in it, and I want dynamically generated css rules to append to the end of the file. However, my code always overwrite the file deleting all the previous data, but…
Abhik
  • 664
  • 3
  • 22
  • 40
0
votes
2 answers

overwritting content of .txt file in php

I need to overwrite the content of a .txt file when I browse a file in a page.I have written a php script for it. Form is given below
121kk
  • 51
  • 8
0
votes
2 answers

file_put_contents create new file

My below script works when the cache file is already present, but does not create the initial first cache file itself. Can somebody help me? The folder permissions are fine.
0
votes
2 answers

create php cache with file_get_contents

I am trying to create a cache file from a menu that takes random data called 'includes/menu.php' the random data is created when I run that file manually, it works. Now I want to cache this data into a file for a certain amount of time and then…