file-put-contents

Write JSON data to text file with PHP [duplicate]

回眸只為那壹抹淺笑 提交于 2021-02-10 19:58:55
问题 This question already has answers here : Issue reading HTTP request body from a JSON POST in PHP (2 answers) How to update/edit a JSON file using PHP [closed] (1 answer) Closed 2 years ago . Problem: I have a script that send JSON data to a PHP file in this way: var xmlhttp = new XMLHttpRequest(); xmlhttp.open("POST", "process-survey.php"); xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xmlhttp.send(JSON.stringify({uid, selected})); The problem is that JSON data

How to download file Using PHP that has delayed force download?

落爺英雄遲暮 提交于 2020-08-06 07:09:21
问题 I am at a situation, where I need to download files from the URL, it is easy with the direct file URLs like https://somedomain.com/some-path/somefile.exe file_put_contents( $save_file_loc, file_get_contents($url_to_download); But what to do when you have delayed force download from the URL which actually prints HTML and how to differentiate those URL? Example URL: https://filehippo.com/download_mozilla-firefox-64/post_download/ EDIT: On above url the file download starts using JS, as I tested

How can I combine or simplify multiple statements

非 Y 不嫁゛ 提交于 2020-07-16 09:48:12
问题 I have repetitive statements and need help to simplify or combine statements They all have similar values and range from jan - dec and the item (sales change to different category in this example sales change to ncvat) changes for 32 different categories and each group has a different submit value if(isset($_POST['submit1'])){ $xml->sales->jan = $_POST['jan']; file_put_contents("2020/data.xml", $xml->asXML()); } ................................... ................................... if(isset(

Crazy PHP fopen / fwrite / file_put_contents / move_uploaded_file bug with binary mode writing on CentOS Linux Adding 0x0D to every 0x0A

天涯浪子 提交于 2020-06-13 05:03:32
问题 Seems the file keeps adding 0x0D to my saved binary files no matter what setting I put in the fopen mode flag. It's not only affecting fopen / fwrite .. but also file_put_contents . file_get_contents I thought was the problem to begin with.. but it turns out this one is actually working okay.. because when I dumped the file using bin2hex() it came out good. I was blaming at first the std::string in C++ for this bug.. but it turns out it doesn't even have anything to do with C++ but it's in

Crazy PHP fopen / fwrite / file_put_contents / move_uploaded_file bug with binary mode writing on CentOS Linux Adding 0x0D to every 0x0A

青春壹個敷衍的年華 提交于 2020-06-13 05:01:27
问题 Seems the file keeps adding 0x0D to my saved binary files no matter what setting I put in the fopen mode flag. It's not only affecting fopen / fwrite .. but also file_put_contents . file_get_contents I thought was the problem to begin with.. but it turns out this one is actually working okay.. because when I dumped the file using bin2hex() it came out good. I was blaming at first the std::string in C++ for this bug.. but it turns out it doesn't even have anything to do with C++ but it's in

file_put_contents not working

杀马特。学长 韩版系。学妹 提交于 2020-01-15 03:55:12
问题 I try to upload something to my ubuntu server by file_put_contents (a converted base64-string as .jpg) with the following code : file_put_contents($filename, base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data))); And yes, all parameters are right, I double checked them. And I'm wondering why it is not working: By the way: I try to upload it to a folder, one level higher then the folder, that is reachable by the url (but even when putting it directly in internet folder, it

file_put_contents overwrites data

*爱你&永不变心* 提交于 2020-01-11 13:26:07
问题 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. ` include_once(CLASS_PATH."fetch_service.php"); $objfetch = new fetchService(); $res = $objfetch->fetch_proxy("*","where account_id='".$_SESSION['account_id']."'"); foreach($res as $result) { $proxyname=$result['proxyname']; $ip=$result['proxyip']; $proxyport=

Is file_get_contents & file_put_contents reliable or can lead to loss of data? Benchmark results

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-06 06:57:31
问题 I was wondering what happens if multiple scripts are sharing same file. I uploaded the test on remote server, where they use HDD to store data. There were 7 tests total, but the family of 6 are compatible. I have 7 files of different size which I uploaded to server and the test. It is loop which reads and writes data from the files. There is 50 microseconds delay in the loop. The loop repeats 50x. I measure the time needed to perform every circle. The differences in the tests (T): Using file

Download files file_put_contents with progress

倖福魔咒の 提交于 2019-12-20 04:06:05
问题 I try to write code with download file and return status (downloaded bytes). To download file I use file_put_contents and it's work. function downloadLink($link,$destination) { $ctx = stream_context_create(); stream_context_set_params($ctx, array("notification" => "stream_notification_callback")); $mb_download = file_put_contents($destination, fopen($link, 'r'),null,$ctx); return $mb_download; } function stream_notification_callback($notification_code, $severity, $message, $message_code,

Can't create text file or append to it in NGINX without CHMOD 777

五迷三道 提交于 2019-12-11 18:32:21
问题 Using Lightsail NGINX instance and got a one line in a PHP file that won't do what I need $s = 'Hello world'; $myfile = file_put_contents('log.txt', $s.PHP_EOL , FILE_APPEND | LOCK_EX); I want it to create the log.txt file if it's not there. If it is there, I want it to append. It does not do either. If I create the file, it doesn't work. Only if I chmod the file to 777 via SSH will it work. However a future piece of work would be to make the file so for reasons beyond the security of 777,