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

file_put_contents doesn't work with json laravel & php

I tried everything to push item into json file but when call file_put_contents("file.json",$data) doesn't work and the page shutdown. Here's my controller code. public function addJson() { $titulo = Input::get('title'); $name =…
StAx
  • 272
  • 1
  • 3
  • 16
6
votes
2 answers

Why can't write info into /tmp directory instead of /var/www/html?

LAMP installed on my local pc, as I know the string xxxx can be written into /tmp/test with below PHP function. file_put_contents("/tmp/test","test1 test2") cat ajax_get.php
user7988893
6
votes
3 answers

PHP: "failed to open stream: Permission denied"

I am getting some interesting results on my server when i try to access any Directory or File via some Function.I have set all my file & directory permissions to 777 and have changed the content owner to Apache but i still get error…
5
votes
2 answers

Foreach loop returns only first index on multidimensional array PHP

Let me explain my situation, I'm making a mailing template for my company. This mailing template has to be completely in HTML. The mailing template contains different products from our shop. The template has boxes with information about the…
Izzy
  • 61
  • 5
5
votes
1 answer

Why is file_put_contents() sometimes throwing a "No error" error?

Why does this code sometimes give a No such file or directory warning but other times a No error warning; Usually gives this error warning; Warning:…
Nigel Alderton
  • 2,265
  • 2
  • 24
  • 55
5
votes
1 answer

Write to text file will not work with the first item clicked

I have an odd question and I have no idea what's wrong. I am coding an interactive map of the United States. The user clicks a state and the click is recording in a text file. Then the number of clicks total is shown on the map. It's basically a…
5
votes
4 answers

file_put_contents(): connect() failed: Permission denied in AWS server

$username_ftp = "user"; $password_ftp = "password"; $file_name = "remote-transfer.txt"; $url = "example.biz/test/" . $file_name; $hostname = "ftp://$username_ftp:$password_ftp@$url"; $content = file_get_contents('index.html'); $options = array('ftp'…
Md Hasibur Rahaman
  • 1,041
  • 3
  • 11
  • 34
4
votes
2 answers

Downloading a CSV file using PHP from an API - with a URL that doesn't end with .csv

I have been trying to download a file from an API in 2 different way without any success: https://example.com/export/banana/by_date/v4?api_token=666&from=$today&to=$today *Notice the file doesn't end with .csv, it just pop out the download file…
Imnotapotato
  • 5,308
  • 13
  • 80
  • 147
3
votes
0 answers

file_put_contents returns alright, but no file is created

I'm trying to write to a file in /tmp directory which has permissions: drwxrwxrwt. When I execute file_put_contents from php -a interactive shell, it works alright and creates a file with the provided content. When I call this function in the code,…
Saqib Ahmed
  • 1,056
  • 14
  • 33
3
votes
2 answers

Is there a better way cycle through these PHP codes, maybe with foreach loop?

I use file_get_contents to grab a remote pricing (updated daily), use substr to keep only the portions I want (stripping out the currency symbols and other data from the output and only keeping the numbers) and use file_put_contents to store it into…
James
  • 41
  • 5
3
votes
1 answer

file_put_contents causes page to refresh

I am calling a file_put_contents() inside of a PHP script that is executed via AJAX. Whenever I execute this script the client page gets reloaded which is not desirable. Is there a way to prevent the PHP script from reloading the page? I have tried…
Matt Butler
  • 476
  • 6
  • 21
3
votes
0 answers

PHP file_put_contents create only empty file

I have a problem with saving files on server (linux). On localhost (Windows) is function OK. umask(007); if (file_put_contents($path, (string) $data) === false) { log("error", "error create file"); } $path is…
Manic Depression
  • 1,000
  • 2
  • 16
  • 34
3
votes
0 answers

file_put_contents is returning true, but the file isn't getting written too.

I have a small PHP script being run when I press a button on some HTML page:
NNNNNNNNNNDelicious
  • 933
  • 3
  • 7
  • 19
3
votes
2 answers

How can I load a remote file using file_get_contents()?

Scratching my head a bit now with this. I am trying to get a file from a remote url. I can save contents from local files, but can't from remote. This works: file_put_contents( 'file1.xml', file_get_contents('file2.xml') ); This…
Oldbej
  • 31
  • 1
  • 3
2
votes
1 answer

HOSTINGER FILE_PUT_CONTENTS HTML2CANVAS : cannot upload the screenshot, but it says that it's not empty

I already tried validating if the canvas/screenshot worked and it says that it did. I guess the problem is that it isn't uploaded to the directory. I also already tried enabling the fileUpload option in the Cpanel of the hostinger. I also tried…
caps
  • 21
  • 2
1
2 3
16 17