fopen

Processing CSV File in PHP that able to cater MS and UNIX Line Break

▼魔方 西西 提交于 2019-12-11 21:14:03
问题 I have a module that process a CSV File as Input. It works fine in my Ubuntu machine, until someone in my team start to use Microsoft Excel to create the csv. As the result, the new input CSV is having ^M ( \r\n ) characters on it, and because of that, my code assumes that the CSV is consist of 1 line only, and all the data is populated to $header. I have changed the read mode to "rt" since the php.net advises to open text in t mode, but the issue is still exist. It seems that rt is only

PHP Write a variable to a txt file

青春壹個敷衍的年華 提交于 2019-12-11 20:11:20
问题 I am trying to get a variable from the query string and write it to a text file. I have tried like this: <?php $content=( $_GET['var'] ); echo $content; $file = fopen("etlLOG.txt","w+"); echo fwrite($file,$content); fclose($file); ?> I get the following errors: Warning: fopen(etlLOG.txt) [function.fopen]: failed to open stream: Permission denied in E:\Users\george\listener.php on line 8 Warning: fwrite(): supplied argument is not a valid stream resource in E:\Users\george\listener.php on line

LinuxC语言编程03:文件I/O

99封情书 提交于 2019-12-11 19:44:13
LinuxC语言编程03:文件I/O 标准I/O 流 文本流与二进制流 流的缓冲类型 预定义的流 流的打开与关闭 流的打开 流的关闭 处理错误信息 流的读写 按字符读写 按字符输入 按字符输出 按行读写 按行输入 按行输出 按对象读写 流的刷新 流的定位 判断流的出错与结束 格式化输入输出 文件I/O 文件描述符 文件的打开与关闭 文件的打开 文件的关闭 文件的读写 文件的定位 目录的访问 文件的访问权限 文件的属性 标准I/O 标准I/O是指标准C中定义的一组输入和输出的API,与操作系统无关,具备可移植性. 流 标准I/O将打开文件的信息抽象成为流(stream),使用 FILE 结构体代表流.标准I/O的所有操作都是围绕 FILE 结构体进行的. 文本流与二进制流 Windows操作系统区分文本流与二进制流,两者间最显著的区别在文本流中 \n 会被替换成 \r\n ,而二进制流不会做这种转换.而Linux操作系统不区分文本流与二进制流,不会做这种转换. 流的缓冲类型 流有三种缓冲类型: 全缓冲: 当流的缓冲区无数据或无空间时才执行实际I/O操作.使用标准I/O打开文件时默认是全缓冲. 行缓冲: 当在输入输出中遇到换行符 \n 时才执行实际I/O操作.当流与终端交互时(输入或输出)是行缓冲. 无缓冲: 直接与文件进行交互,不进行缓存.向标准错误流输出时是无缓冲. 预定义的流

How can I force PHP's fopen() to return the current version of a web page?

倖福魔咒の 提交于 2019-12-11 19:38:38
问题 The current content of this google docs page is: alt text http://www.deviantsart.com/upload/i9k01q.png However, when reading this page with the following PHP fopen() script, I get an older, cached version: (source: deviantsart.com) I've tried two solutions proposed in this question (a random attribute and using POST) and I also tried clearstatcache() but I always get the cached version of the web page. What do I have to change in the following script so that fopen() returns the current

PHP curl: curl_setopt() fopencookie failed

人盡茶涼 提交于 2019-12-11 18:08:56
问题 I'm trying to write a script, which would cache images, but am stuck with the following error message: Nov 4 12:55:19 centos httpd: PHP Fatal error: curl_setopt() [<a href='function.curl-setopt'>function.curl-setopt</a>]: fopencookie failed in /var/www/html/proxy3.php on line 6 I have prepared a simpler script which still has this problem: <?php #phpinfo(); $fh = fopen('/tmp/yahoo.html', 'xb'); if ($fh) { $ch = curl_init('http://www.yahoo.com/'); curl_setopt($ch, CURLOPT_FILE, $fh); # XXX the

PHP: Get fopen() HTTP response error code

时光总嘲笑我的痴心妄想 提交于 2019-12-11 17:49:58
问题 I would like to get the HTTP error code while opening a remote file via fopen() function. I have the following code: $remote = fopen ($url, "rb"); If the URL is fine, the file would be opened. Otherwise, fopen triggers an error message similar to Warning: fopen(url): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found . I know that adding a @ before the fopen() would suppress the error message, but how can I get the http error code instead? Here, I want to get HTTP/1.1 404 Not

cURL and fopen slow in browser, quick via command line

霸气de小男生 提交于 2019-12-11 16:51:18
问题 I have an issue where I am trying to connect to a remote server to retrieve data. There are 2 methods. One is using fopen and the other is using cURL. Both of them are painfully slow in the browser, to a point where it loads and nothing happens. It will just return a "ERR_CONNECTION_RESET" in Chrome. However, when I run the same script via command line (Apache, Ubuntu), it works rapidly. Are there any obvious reasons why this may be? This data fetch method works fine on other servers and in

Create a file and its parents directories in c

时光总嘲笑我的痴心妄想 提交于 2019-12-11 16:42:03
问题 I didn't find any relevant answer for this question. I want to create a file and its parent directory at the same time: example: FILE *fd2 = fopen("test/test", "w+"); where test/ doesn't exist. Is there a way to do this? 回答1: In Linux you can do it with the following code #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> ... /* check if directory exist */ struct stat status = { 0 }; if( stat("test", &status) == -1 ) { /* create it */ mkdir( "test", 0700 ); } /* open file */

Trying to piece together a large html document with input from a form

帅比萌擦擦* 提交于 2019-12-11 16:16:45
问题 I'm trying to build a document out of its various parts. Destination document does not get any content. Can you possibly tell me what I'm doing wrong here ? I have a begin.txt with HTML content and an end.txt which I want to keep having the new code ( newarticle.txt ) added to the beginning of so it flows forward every time a new addition is made. Then I want it all put together into articles.html . <?php $v1 = $_POST["url"]; //You have to get the form data $v2 = $_POST["description"]; $v3 =

Is php's fopen incompatible with the POSIX open for pipes

别说谁变了你拦得住时间么 提交于 2019-12-11 15:06:33
问题 Why is this so darn confusing. PHP's fopen will not open a file for reading unless there is data in the pipe waiting to be read (according to this comment). The POSIX specification for C's open states that, depending on the state of the O_NONBLOCK flag, when opening a pipe for writing, open will either block the calling process or return an error if no process has the file open for reading. Is this difference reconcilable? 回答1: No. Php should signal C that it is expecting a connection and