Questions tagged [fwrite]

fwrite stands for file write. It is a function available with PHP, C, C++, etc. for writing the contents of string to the file stream pointed to by handle.

fwrite stands for file write. It is a function available with PHP, C, C++, etc. for writing the contents of string to the file stream pointed to by handle.

PHP fwrite

Visual Studio fwrite

C++ fwrite

1762 questions
5
votes
2 answers

How do you permit PHP to write to a file without compromising server security

I am often confronted with negative comments whenever I want to have a PHP script write output to a file on the server. I use the fopen(), fwrite() and fclose() functions. The only way I know how to make this happen is to either set the permissions…
H. Ferrence
  • 7,906
  • 31
  • 98
  • 161
5
votes
3 answers

What's the best way to read from and then overwrite file contents in php?

What's the cleanest way in php to open a file, read the contents, and subsequently overwrite the file's contents with some output based on the original contents? Specifically, I'm trying to open a file populated with a list of items (separated by…
Phillip
  • 5,366
  • 10
  • 43
  • 62
5
votes
2 answers

fwrite() File Corruption C++

I'm somewhat of a newbie to C++ (moving from C#) so I'm not exactly sure what's going on here. What I'm trying to do is read an image out of a file and write it to an output file, but whenever I do parts of the file appear to be corrupt. I've…
Lander
  • 3,369
  • 2
  • 37
  • 53
5
votes
3 answers

What is the purpose of having both the paramers size and nmemb in `fwrite()`?

fwrite() is declared as this. size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); But the actual number of bytes written is just size * nmemb. So why not just specify the number of bytes? Why it is necessary to specify both…
user1424739
  • 11,937
  • 17
  • 63
  • 152
5
votes
3 answers

r Write text and dataframe to file

What is the best way to write to a file some text followed by a data frame? The text is created by pasting variables into strings. Example desired output: Here is some text. This line has a variable: Hello World Data frame below the…
conor
  • 1,204
  • 1
  • 18
  • 22
5
votes
1 answer

How to detect insufficient disk space when using stdio file operations in C/C++?

I am making a small program as follows: void reserve_file_space(char* file_path, size_t amount) { FILE* fp = fopen(file_path, "w+b"); if(!fp) { printf("could not create a new file\n"); return; } int fseek_ret =…
duong_dajgja
  • 4,196
  • 1
  • 38
  • 65
5
votes
1 answer

fwrite writes to the end of the file after seeking to the end

I have a set of list items those I read to the structure. This code should replace existing item. A user enters position (1..n) and the corresponding record should be replaced. But it doesn't work, the record puts to the end of file. What's wrong? …
Dmitry Shepelev
  • 152
  • 2
  • 10
5
votes
2 answers

C++ Text file won't save in Unicode, it keeps saving in ANSI

So basically, I need to be able to create a text file in Unicode, but whatever I do it keeps saving in ANSI. Here's my code: wchar_t name[] = L"‎中國哲學書電子化計劃"; FILE * pFile; pFile = fopen("chineseLetters.txt", "w"); fwrite(name,…
Kelv
  • 81
  • 1
  • 6
5
votes
1 answer

How do I overwrite X bytes on offset Y with fwrite()?

All I can find using fopen() and fwrite() in C is to delete all contents and start writing again or append to the end of the file. What if I need to go to some offset in the file and overwrite a few bytes? Is that possible with some function?
rfgamaral
  • 16,546
  • 57
  • 163
  • 275
5
votes
2 answers

CSV resize columns depending on the content

I wonder if it is possible to set the size of columns based on the content they contain. I would like when you open the CSV once it has been directly generate columns are the right size. For write in the CSV I have this code : $csvFile =…
mortiped
  • 869
  • 1
  • 6
  • 28
5
votes
1 answer

fwrite() more than 2 GiB?

I have a set of files that I want to concatenate (each represents a part from a multi-part download). Each splitted file is about 250MiB in size, and I have a variable number of them. My concatenation logic is straight-forward: if…
Alix Axel
  • 151,645
  • 95
  • 393
  • 500
5
votes
4 answers

Writing and reading unsigned chars to binary file

I am writing a simple program that writes to a binary file, closes it and then reads the data that was just written. I am trying to write an array of unsigned characters. I am experiencing some issues while reading the data. I am not exactly sure if…
RagHaven
  • 4,156
  • 21
  • 72
  • 113
5
votes
2 answers

Editing a PHP File, with another php file, using Fwrite

My last question wasn't explained very well. What I'm trying to do here is insert data into a PHP File, Using the fwrite feature on another .php file. To keep this simple, I'm labelling the one I want data inserted as file.php and the one I'm using…
Ron
  • 379
  • 3
  • 8
  • 20
5
votes
2 answers

How LOCK works for writing logs into flat file?

Read concurrency of flat files is almost unlimited (correct me if I'm wrong); but how is the concurrency for write? Consider a simple access log writing (for visits) in PHP as to append a line of access detail ended with \n fopen(); // in append…
Googlebot
  • 15,159
  • 44
  • 133
  • 229
4
votes
3 answers

fwrite if file doesn't exist?

Is it possible to only write a file in PHP if it doesn't exist? $file = fopen("test.txt","w"); echo fwrite($file,"Some Code Here"); fclose($file); So if the file does exist the code won't write the code but if the file doesn't exist it will create…
Josh
  • 2,835
  • 1
  • 21
  • 33