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

Adding parameters to URLs from HTML file

I'm creating a local php script to manipulate a HTML file exported from Photoshop. I need to add some parameters to every url . This is what I've tried: $newHtmlFile = 'exported.html'; //HTML file exported from photoshop $htmlContent =…
maeq
  • 1,073
  • 1
  • 12
  • 23
0
votes
1 answer

php writing to a file produces output with syntax errors and wrong order of contents

I created a function to store settings to a file (in a readable way) so that the settings can be modified by directly editing the file later on. I used the method described here. $data = "
Aryan
  • 144
  • 1
  • 7
0
votes
1 answer

file_put_contents doesn't save appended lines when on server (php)

The first line saves fine and in subsequent calls the additional text appends perfectly when run locally but when run on the server only the first line saves and then seems to ignore all following attempts to save. Even if the file on the server is…
Andrea
  • 41
  • 2
0
votes
2 answers

How to add Tabs and Line Breaks from Array using file_put_contents

I am connecting to a SQLite database. I use the following query to get the results: $db = new SQLite3('sshTunnel.sqlite'); $results = $db->query('SELECT * FROM TUNNEL'); Now, I want to add tabs and line breaks from the row array using…
sjantke
  • 605
  • 4
  • 9
  • 35
0
votes
1 answer

My php script sometime write blank data

I have a simple script, just count how many click on a link, when the link clicked, a php script read "counter.txt" file for link ID/URL/Label/Count then plus 1 on count, write to "counter.txt", then redirect. counter.txt : Label…
Tran
  • 185
  • 2
  • 4
  • 15
0
votes
2 answers

Create a TXT File with PHP that contains all Data (*) FROM a Table

I am trying to create a TXT file with PHP. This works fine. Unfortunately, it seems that I do not have the correct syntax, because there is no content inserted using the file_put_contents function to put the data from my SQLite table into the TXT…
sjantke
  • 605
  • 4
  • 9
  • 35
0
votes
0 answers

Php, file_put_contents within body tag

Im using Dom parser to extract content from html page within body tag something like: $html = file_get_contents('index.php'); libxml_use_internal_errors(true); $dom = new DOMDocument(); $dom->loadHTML($html); $body =…
Alko
  • 1,421
  • 5
  • 25
  • 51
0
votes
0 answers
0
votes
0 answers

file put contents how to set a path

I am using file put contents and set a file name but file saved on the directory where the script was written. How to do to set the full path to save to disc or desktop. Something like browse window and save path. $fileName = 'etykieta_' .…
usmauriga
  • 73
  • 1
  • 1
  • 5
0
votes
1 answer

file_put_contents on OS X El Capitan

i am new to Mac OS X. Currently, i want to place a localhost on my brother OS X and host php files for him. I made a php that can take a picture and save it directly to the folder. The code is working on my windows 7 PC and i can use it normally.…
efraim
  • 87
  • 1
  • 2
  • 9
0
votes
1 answer

PHP:DOMDocument::load(): I/O warning : failed to load external entity (external rss feed and cache file)

I need to show on my page, the latest entries from an external RSS feed. I made a simple rss reader which uses a cache file. It perfectly works on my test environment but when I put it on my website, I got an error every time the cache file has to…
Fabio Maccari
  • 57
  • 1
  • 2
  • 7
0
votes
0 answers

PHP Save or Load using FileChooser

I have two buttons where, actually, pushing, I can save and then load a static file using: file_put_contents('results.json', $result); (Save button) $arr1= json_decode(file_get_contents('results.json'),true); (Load button) Using these…
0
votes
0 answers

Why file_put_contents is not working in register_shutdown_function?

I'm creating an error handler, but I have a dark trouble... After runing my code, I see this in my monitor: Function is working! Fatal error: Class 'NotExistingClass' not found in D:\OpenServer\domains\models_statistic\run.php on line 39…
0
votes
1 answer

PHP File Writing (fwrite / file_put_contents) speed/optimization

So, i have a database with big data. The data to use is currently about 2,6 GB. All the data need to be written to a text file for later use in another scripts. The data is being limited per file and splitted in multiple parts. 100 results per file…
Ramon Bakker
  • 1,075
  • 11
  • 24
0
votes
1 answer

Save file with file_put_contents in folder

I've an image from this link. I want to copy it to my server. This is what I've tried: $url = 'http://tex.z-dn.net/?f=4%5E%7B13%7D%2A2%5E%7B-10%7D%3A16%5E%7B3%7D '; function GetImageByURL($url, $path = null) { $opts = array(CURLOPT_URL =>…
Art Noimann
  • 115
  • 3