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
-1
votes
2 answers

Append to file without adding newlines using PHP

I want to take some integers from the apriori_main table and store them into a text file as comma separated values. For each iteration I use file_put_contents to write data on the next line. Using fwrite gives the same result. The output I want in…
-1
votes
1 answer

PHP - How can I write data from a
to an excel file using file_put_contents()?

PHP - How can I write data from a
to an excel file using file_put_contents()?
helper
  • 1
-1
votes
1 answer

file_put_contents and $_SERVER data

$file = 'userdata.txt'; file_put_contents($file, print_r($_SERVER['HTTP_USER_AGENT']), FILE_APPEND); In userdata.txt I have: 1 (don't know why) Finally, I want to save to .txt $_SERVER['HTTP_USER_AGENT'] and $_SERVER['REMOTE_ADDR']
jimmynew
  • 9
  • 3
-1
votes
1 answer

Is file_put_contents secure to upload files

I am using file_put_contents() function to write the files on server. I have split the file on client side and send chunks on server. using file_put_contents I am writing that content on server side file. So I worry, is that a secure way to do it?
infinityKK
  • 40
  • 1
  • 5
-1
votes
2 answers

File_put_content of various images and rename with count

I have following code: $url = explode('\n', $urls); $count = 0; foreach($url as $image) { $img = 'c://wamp/www/www.mysite.com/uploads/images/cat1/image'.$count++.'.png'; file_put_contents($img, $image); } In variable $urls have…
Gislef
  • 1,555
  • 3
  • 14
  • 37
-1
votes
1 answer

Adding Files After mkdir

I can't quite figure out how to add files from a sample directory that I have. I would appreciate some help. I have successfully created a new directory when ever a user inputs their username, but the contents are empty. Edit: I've created the…
Joshua Adams
  • 39
  • 1
  • 8
-2
votes
1 answer

Script to replace comma "," by "->" as multiple value separator on category field of csv (only on this filed of csv)

I need to to replace comma "," by "->" as multiple value separator on category field of csv, on a php script. In the attached example csv piece, the field value on first row is ;ALIMENTACIÓN,GRANEL,Cereales legumbres y frutos secos,Desayuno y entre…
iostream
  • 11
  • 1
-2
votes
1 answer

PHP: Save the file returned by wget with file_put_content

I'm replacing a function that downloads a file with cURL and returns its content in a variable, then outside the function the code writes this variable to a file with file_put_content. Because of requirements of the system I have to use wget now, so…
tharok
  • 37
  • 1
  • 8
-2
votes
1 answer

How do you put content in xml file using file_put_contents in sub-child element

I know how to put content to child element I google and can't find solution to put content to sub-child element. I have following structure in my xml file
-2
votes
2 answers

PHP - Detecting image filesize before saving image

I am using the following code to save an image from a URL but sometimes the image URL is bad and there is no image there, OR there is an issue with the image and it saves a zero size file.
omega1
  • 1,031
  • 4
  • 21
  • 41
-2
votes
1 answer

Read PDF from external URL, and automatically download when the button was triggered

I would like to download a pdf from my external URL, store it in my server and download it when the button was triggered by click by the user. I have tried to store it to my server and its success, but then I don't know how to automatically download…
baimWonk
  • 761
  • 1
  • 5
  • 11
-2
votes
2 answers

array_diff return a string without an array

I'm trying to clean my db if($var == true){ $db = file('db.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); shuffle($db); $db2 = file('db2.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $cleaner = array_unique ($db); …
-2
votes
2 answers

PHP - Everytime I save to file the old data gets overwritten

$testarray['player1'] = $player1Plays; $testarray['player2'] = $player2Plays; $testarray['result'] = $result; print_r ($testarray); $yoyo = serialize ($testarray); $file = 'prevdata.dat'; fopen ($file, 'w'); file_put_contents($file, trim($yoyo) .…
Baker2795
  • 237
  • 3
  • 12
-2
votes
1 answer

How to add data to a JSON file without completely overwriting it's current content? (php)

Let's say I have a info.JSON file on my server, with the following data: {"firstName":"John","age":"37"} And in PHP, I want to add another key/value pair (somebody's middle name for example) to the info.JSON file. If I use the file_put_contents()…
bool3max
  • 2,748
  • 5
  • 28
  • 57
-2
votes
3 answers

Best way to check if a file exists before execute a file_put_contents function

As the title says I'm searching for the best way to check if a file exists before execute a file_put_contents function. It's better to add a number after the filename? or It's better to generate the filename with a date/time after the name? In my…
JBoY
  • 51
  • 3
  • 13
1 2 3
16
17