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
0 answers

php file_put_contents takes 2sec and is not blocking

I'm currently doing a config.inc file
Neil
  • 390
  • 2
  • 14
0
votes
1 answer

Download to folder in server from url, PHP

I have in my database several image links in an array. I want to download these to a folder in my server renaming the images to 0.jpeg, 1.jpeg, 2.jpeg and so on. I only managed to insert 1 with the name of 0.jpeg. $result2 = $d->query("SELECT photos…
Helenp
  • 143
  • 2
  • 15
0
votes
2 answers

Update array in a file

I have an include with a single array in it that holds 3 instructions; a "y/n" switch and a start and end date. The include meetingParams.php looks like this: I want to update those array…
parboy
  • 67
  • 8
0
votes
1 answer

file_put_contents auto increment duplicate int value in php?

I have small code. total_request.txt is text file have content value =1 $file = 'total_request.txt'; $count = file_get_contents( $file ); echo $a = $count + 1; file_put_contents( $file, $a ); code output value: 2 but file total_request.txt have…
cudan706
  • 1
  • 1
0
votes
1 answer

PHP: file_put_contents() strips last tab (\t)

I wrote a webservice which allows (after authentication of course) to transfer file contents via post, which gets written into a file. Everything works fine, unless the last char(s) are a tab or a tab followed by a linebreak, which both get…
dwing265
  • 120
  • 1
  • 13
0
votes
0 answers

How to protect a file while still allowing file_put_contents to append it?

Let's assume you have a blog with user registration and for various reasons you decide to keep some of the less important user information in a file. You use file_put_contents to create and then append the file. Obviously you still want to protect…
P.Pal
  • 63
  • 9
0
votes
0 answers

file_put_contents appending rows to a CSV file in PHP

If I have a CSV file with 5000 rows on my server, does file_put_contents read the whole file into memory before appending a new row? I have a custom tracker PHP script that appends one line to a server side CSV file each time a new web visitor…
AliC
  • 81
  • 1
  • 10
0
votes
1 answer

file_put_contents from multiple requests into specific format PHP

I want to put content from 2 or more requests into a file that will be formatted as: customer | invoice Below I managed to get both request to be posted, but how do I get them to be posted in the below format: Customer1 | Invoice1 Customer2 |…
Libby1889
  • 13
  • 2
0
votes
0 answers

file_get_contents failure on windows

I have a PHP CLI application that creates a file with file_put_contents then listens for changes to that file. If the filemtime changes then I try to get the content with file_get_contents. It often fails to retrieve the contents on windows. This…
0
votes
1 answer

How to remove a line from text file using php with specific structure

I have a css file with this content: #firstdiv { width:100%; height:200px; } #seconddiv { width:80%; height:70px; } #thirddiv { width:80%; height:70px; } #firstdiv { color:red; background:yellow; } #seconddiv { color:red; background:green;…
0
votes
1 answer

Downloading PDF with PHP

$ext = pathinfo($url, PATHINFO_EXTENSION); if ( $ext == 'pdf' || $ext == 'doc' || $ext == 'docx') { file_put_contents('product-docs/'.$slug.'-'.$r.'.'.$ext, $url); } I'm expecting this code to download the document, instead it saves the file with…
eozzy
  • 66,048
  • 104
  • 272
  • 428
0
votes
1 answer

file_put_contents sometimes works, not always

I have a script that copies the output of twig / email to a tmp file that we need to store for legal purposes. Firstly this was done by using fopen, fwrite, close. That worked for years, all of sudden it stopped working and the files. Then we…
Peter Fox
  • 1,239
  • 2
  • 11
  • 31
0
votes
0 answers

failed to open stream: No such file or directory:file_put_contents

i am trying to upload image and i get this error this is the error i get i dont have any idea what to do i try to change 'src' but the picture cant upload. i try to change file_put_contents but this is doesn't work. static function…
Liran Atli
  • 43
  • 1
  • 9
0
votes
1 answer

Copy image from url results in corrupt image

I have a problem trying to copy the image from this link into my local directory. You can find 2 other images with the same problem: First http://awards.createdirect.ro/thumb/900/900/image/award/v1/Despre%20Spa%20200.jpg Second…
0
votes
2 answers

Adding text on each line of the document with php

I want to add exact same text on each line of the file but can't make it. The reason is because I have 1k+ rows and doing this manually will be pain. What I have so far is this: $file_data = "my string \n"; $file_data .=…
S.I.
  • 3,250
  • 12
  • 48
  • 77