fopen

fopen problem - too many open files

廉价感情. 提交于 2019-12-23 12:28:57
问题 I have a multithreaded application running on Win XP. At a certain stage one of a threads is failing to open an existing file using fopen function. _get_errno function returns EMFILE which means Too many open files. No more file descriptors are available . FOPEN_MAX for my platform is 20. _getmaxstdio returns 512. I checked this with WinDbg and I see that about 100 files are open: 788 Handles Type Count Event 201 Section 12 File 101 Port 3 Directory 3 Mutant 32 WindowStation 2 Semaphore 351

Open text files in matlab and save them from matlab

爷,独闯天下 提交于 2019-12-23 05:46:26
问题 I have a big text file containing data that needs to be extracted and inserted into a new text file. I possibly need to store this data in an cell/matrix array ? But for now, the question is that I am trying to test a smaller dataset, to check if the code below works. I have a code in which it opens a text file, scans through it and replicates the data and saves it in another text file called, "output.txt". Problem : It doesn't seem to save the file properly. It just shows an empty array in

fopen can't create file

♀尐吖头ヾ 提交于 2019-12-23 05:08:32
问题 I’m working on something which requires PHP to make files and folders. I'm using fopen to create the file. However, it doesn't seem to work. When I was writing the code, I was on windows with WAMP and everything was working but when I moved the site to Ubuntu server the script simply doesn't work. This is the code I’m using for the creation on the file and the ziping mkdir($sessionid, 777); // create the server.properties $server_config = fopen("$sessionid/server.properties",'a'); $config =

fopen 't' compatibility mode in php

匆匆过客 提交于 2019-12-23 02:51:07
问题 It is said, that fopen can use t mode to convert \n to \r\n . So, questions: 1) How should i use t mode when i need to read and write ( r+ )? Should it be r+t or rt+ or tr+ ? Same question for b , should i write r+b or how? 2) I've tried all variants on debian linux to convert file, that contains only \n to \r\n using magic mode t (wanna understand how it works). But it does not work. What am I doing wrong? When t mode works? Here is my code: // Write string with \n symbols $h = fopen('test

PHP fopen - Write a variable to a txt file

断了今生、忘了曾经 提交于 2019-12-22 09:58:00
问题 I've checked this and its not working for me ! PHP Write a variable to a txt file So this is my code,please take a look ! I want to write all the content of the variable to the file. But when i run the code,its only write the last line of the content ! <?php $re = '/<li><a href="(.*?)"/'; $str = ' <li><a href="http://www.example.org/1.html"</a></li> <li><a href="http://www.example.org/2.html"</a></li> <li><a href="http://www.example.org/3.html"</a></li> '; preg_match_all($re, $str, $matches);

PHP can't read files containing PHP code as text files

大城市里の小女人 提交于 2019-12-22 09:49:00
问题 I've stumbled upon the following pecularity: $handle = fopen(realpath("../folder/files.php"), "r"); can't read a file, but as soon as I remove php tags from the file, it becomes readable and my scripts prints non-empty file content on the page. Also, file.php is never ever executed, so I wonder why it is the problem. I guess somehow Apache or PHP doesn't let read files containing php tags PHP as just text. How can I enable it for my particular file (course doing it globally would be unsecure)

初学PHP读取CSV文件

和自甴很熟 提交于 2019-12-22 00:50:49
php中有针对csv函数:fgetcsv array fgetcsv ( int $handle [, int $length [, string $delimiter [, string $enclosure]]] ) handle 一个由 fopen()、popen() 或 fsockopen() 产生的有效文件指针。 length (可选)必须大于 CVS 文件内最长的一行。在 PHP 5 中该参数是可选的。如果忽略(在 PHP 5.0.4 以后的版本中设为 0)该参数的话,那么长度就没有限制,不过可能会影响执行效率。 delimiter (可选)设置字段分界符(只允许一个字符),默认值为逗号。 enclosure (可选)设置字段环绕符(只允许一个字符),默认值为双引号。该参数是在 PHP 4.3.0 中添加的。 和 fgets() 类似,只除了 fgetcsv() 解析读入的行并找出 CSV 格式的字段然后返回一个包含这些字段的数组。 fgetcsv() 出错时返回 FALSE,包括碰到文件结束时。 首先使用fopen(file_url_name,mode) mode中有: 'r' 只读方式打开,将文件指针指向文件头。 'r+' 读写方式打开,将文件指针指向文件头。 'w' 写入方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。 'w+'

How can you catch a “permission denied” error when using fopen in PHP without using try/catch?

非 Y 不嫁゛ 提交于 2019-12-21 21:53:02
问题 I just received an error report for one of my scripts regarding a permission denied error when the script tries to open a new file using 'w' (writing) mode. Here's the relevant function: function writePage($filename, $contents) { $tempfile = tempnam('res/', TINYIB_BOARD . 'tmp'); /* Create the temporary file */ $fp = fopen($tempfile, 'w'); fwrite($fp, $contents); fclose($fp); /* If we aren't able to use the rename function, try the alternate method */ if (!@rename($tempfile, $filename)) {

C fopen mode parameter

我的未来我决定 提交于 2019-12-21 17:37:56
问题 Why is the 'mode' paramter for fopen in C given by a string? It would make more sense (in my way of thinking) for it to be a bitmask or the likes. The overhead a string necessitates is inefficient and unnecessary. 回答1: C11 §7.21.5.3 The fopen function The argument mode points to a string. If the string is one of the following, the file is open in the indicated mode. Otherwise, the behavior is undefined.271) In the footnote: 271) If the string begins with one of the above sequences, the

Can fopen be used to open the URL

心不动则不痛 提交于 2019-12-21 13:10:44
问题 Is fopen("tftp://1.1.1.1/file.txt","rb"); a valid statement? Can urls be opened using fopen in C programming? 回答1: No, but you can use libcurl, an example: #include <stdio.h> #include <curl/curl.h> /* * This is an example showing how to get a single file from an FTP server. * It delays the actual destination file creation until the first write * callback so that it won't create an empty file in case the remote file * doesn't exist or something else fails. */ struct FtpFile { const char