fopen

How to check which files I fopen'ed on Windows?

I received a "Too many open files" error when tried to do fopen (C++, Windows XP). Probably it happened because somewhere in my program I open files without closing them. Is there a way on Windows to see a list of all open file descriptors (or all files that my program fopened)? ...

Can "\Device\NamedPipe\\Win32Pipes" handles cause "Too many open files" error?

Continuing from this question: When I am trying to do fopen on Windows, I get a "Too many open files" error. I tried to analyze, how many open files I have, and seems like not too much. But when I executed Process Explorer, I noticed that I have many open handles with similar names: "\Device\NamedPipe\Win32Pipes.00000590.000000e2", "\...

pound sign in CSV file are not read during PHP fopen

Hi, I am having a problem, pound signs and single quotes are being read from a file as � My code is below: $fh = fopen($_FILES['importFile']['tmp_name'], "r"); $contents = fread($fh, filesize($_FILES['importFile']['tmp_name'])); var_dump($contents); Does anybody know how to fix this issue. I know its an encoding issue but unsure as...

How do I clear the contents of a file using c?

I'm writing some code so that at each iteration of a for loop it runs a functions which writes data into a file, like this: int main() { int i; /* Write data to file 100 times */ for(i = 0; i < 100; i++) writedata(); return 0; } void writedata() { /* Create file for displaying output */ FILE *data; data...

Passing char * into fopen with C.

Hey there, I'm writing a program that passes data from a file into an array, but I'm having trouble with fopen (). It seems to work fine when I hardcode the file path into the parameters (eg fopen ("data/1.dat", "r");) but when I pass it as a pointer, it returns NULL. Note that line 142 will print "data/1.dat" if entered from command l...

How to get fopen to timeout properly

hey all, I have the following snippet of php code if($fp = fopen($url, 'r')) { stream_set_timeout($fp, 1); stream_set_blocking($fp, 0); } $info = stream_get_meta_data($fp); I'd like the request to timeout after 1 second... if I put a sleep(20) in my $url that I'm reading it just waits the whole 20 seconds and never times out...

fopen create new file that not exists

Hey, I am trying to either create a file that doesn't exist or write to a file that already does. within a php file I am trying this: $file = fopen("data.txt", "a"); fwrite($file, "\n" . $name); fwrite($file, "," . $lastname); fwrite($file, "," . $email); fclose($file); I am running Apache under windows Xp and...

segfault during fclose()

fclose() is causing a segfault. I have : char buffer[L_tmpnam]; char *pipeName = tmpnam(buffer); FILE *pipeFD = fopen(pipeName, "w"); // open for writing ... ... ... fclose(pipeFD); I don't do any file related stuff in the ... yet so that doesn't affect it. However, my MAIN process communicates with another process through shared mem...

fopen / fopen_s and writing to files

Hi, I'm using fopen in C to write the output to a text file. The function declaration is (where ARRAY_SIZE has been defined earlier): void create_out_file(char file_name[],long double *z1){ FILE *out; int i; if((out = fopen(file_name, "w+")) == NULL){ fprintf(stderr, "***> Open error on output file %s", file_name)...

Reading a .dat file as "rb" read binary

I have a folder \folder\ above the webroot that contains .php, .inc, .dat files the .php can access the .inc no problem but when the .inc tries to access the .dat using fopen('mydat.dat', "rb"); it gives an error that it can't find mydat.dat inside \folder\myinc.inc Of course it can't find it since .inc is a file not a folder. Why i...

Not able to open a file in php

The code chokes at fopen(): <?php ini_set('display_errors',1); error_reporting(E_ALL); $fp = fopen("/path/to/file/some_file.txt","a") or die("can't open file"); fwrite($fp,"some text"); fclose($fp); ?> And the resulting web page says: "Warning: fopen(/path/to/file/some_file.txt) [function.fopen]: failed to open stream: Pe...

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

Hi, 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? ...

Performance of fopen vs stat

Hello, I'm writing several C programs for an embedded system where every bit of performance we can squeeze out will matter. Part of that is accessing log files. When determining if a file exists, is there any performance difference between using open / fopen, and stat ? I've been using stat on the assumption that it only has to do a q...

php file error. silly small problem

works fine on the desktop with xampp but when i upload it to my webhost it doesnt. The file x.csv is in the same dir $csv_file = "x.csv"; $handle = fopen(($csv_file), "r"); the error i get is- fopen(x.csv): failed to open stream: No such file or directory in /var/www/html/x/admin/import_one.php on line 12 Where am I going wrong? ...

Getting the title of a page in PHP

Hi. When I want to get the title of a remote webiste, I use this script: function get_remotetitle($urlpage) { $file = @fopen(($urlpage),"r"); $text = fread($file,16384); if (preg_match('/<title>(.*?)<\/title>/is',$text,$found)) { $title = $found[1]; } else { $title = 'Title N/A'; } return $title; ...

Using fopen and str_replace to auto fill a select option

Hi Everyone, I have this file 'gardens.php', which pulls data from a table called 'generalinfo' and I use fopen to send that data to a file called 'index.html'. Here is the issue, only one option is filled. I have a demo running here Garden Demo <-- this is a new updated page and location, there are more errors than I have locally If an...

Is there a function that can read a php function post-parsing?

I've got a php file echoing hashes from a MySQL database. This is necessary for a remote program I'm using, but at the same time I need my other php script opening and checking it for specified strings POST parsing. If it checks for the string pre-parsing, it'll just get the MySQL query rather than the strings to look for. I'm not sure ...

Print the first line of a file

void cabclh(){ FILE *fp; char *val, aux; int i=0; char *result, cabeca[60]; fp=fopen("trabalho.txt","r"); if(fp==NULL){ printf("Erro ao abrir o ficheiro\n"); return ; } val=(char*)calloc(aux, sizeof(char)); while(fgetc(fp)=='\n'){ fgets(cabeca,60,fp); prin...

Editing a remote file on-the-fly with PHP

Hi, I have a requirement to edit a remote text file on-the-fly, the content of which currently stands at ~1Mb. I have tried a couple of approaches and both seem to be clunky or hog memory which I can't rely on. Thinking out logically what I'm trying to achieve is: FTP to a remote server. Download a copy of the file for backup purpos...

why do i have to open a file in binary mode to write in it in c?

fprintf(file, "%d %d %d", array[0], array[1], array[2]); for this statement to work i have to open the file in 'wb' mode rather than 'w' mode . How does a binary mode make the syntax work? ...