fopen

Why doesn't PHP 7.2 fopen(/tmp, a) write to the file?

本小妞迷上赌 提交于 2020-01-13 13:13:07
问题 I have an old "PHPDBG" function that lets me "printf" to a text file. I've had PHPDBG.inc "since forever" (at least since PHP 4.x days), but it doesn't seem to be working in my current configuration (ubuntu18, Apache 2.4.29 and PHP 7.2). Specifically: I can't open the file ($fp is null) ... /tmp/PHPDBG.txt never gets created (because of the fopen failure) /tmp should be world-writable ... and ... I don't seem to be able to get a PHP error in the Apache error.log, or get anything meaningful

C - writing output to a file

回眸只為那壹抹淺笑 提交于 2020-01-13 07:16:09
问题 EDIT: void print(const int *v, const int size) { FILE *fpIn; fpIn = fopen("char-array.txt", "a"); int i; if (v != 0) { for (i = 0; i < size; i++) { printf("%d", (int)v[i]); fprintf(fpIn, "%d\n", (int)v[i]); } perm_count++; printf("\n"); } fclose(fpIn); } I guess this is a relatively simple question :) Basically the program is using a permutation algorithm, and printing the output to standard output in the console. I also want to write the content to a file via fprintf I assume. Though I cant

Find if a value exist in a CSV file with PHP

走远了吗. 提交于 2020-01-11 06:21:50
问题 This is my code to check if a row of my .csv file contains a specific name, but it does not work. I think it has something to do with the if statement. $file_handle = fopen("sources.csv", "r"); while (!feof($file_handle) ) { $line_of_text = fgetcsv($file_handle, 1024); if ($line_of_text[0] = 'paul') { echo 'Found'; } } fclose($file_handle); I am trying to check in sources.csv files, for the name 'Paul' . I can't use a database like MySQL for technical reasons. 回答1: Since you haven't provided

PHP读取csv文件的内容

纵饮孤独 提交于 2020-01-11 05:06:35
一次性读取csv文件内所有行的数据 <?php $file = fopen('windows_2011_s.csv','r'); while ($data = fgetcsv($file)) { //每次读取CSV里面的一行内容 //print_r($data); //此为一个数组,要获得每一个数据,访问数组下标即可 $goods_list[] = $data; } //print_r($goods_list); /* foreach ($goods_list as $arr){ if ($arr[0]!=""){ echo $arr[0]."<br>"; } } */ echo $goods_list[2][0]; fclose($file); ?> 读取csv文件的某一行数据 <?php function get_file_line( $file_name, $line ){ $n = 0; $handle = fopen($file_name,'r'); if ($handle) { while (!feof($handle)) { ++$n; $out = fgets($handle, 4096); if($line==$n) break; } fclose($handle); } if( $line==$n) return $out; return false; }

fopen(file,w+) truncates the file before I can check if it's locked with flock()

我是研究僧i 提交于 2020-01-11 03:16:05
问题 I have a function which receives a filename and a json object to write to a text file. The object is updated and needs to entirely replace the current contents of the file. Each site visitor has their own file. Multiple rapid changes create a situation where the file is truncated by fopen(file,w+) , then not written to as it's locked. End result is empty file. I'm sure there's a standard simply way to do this as it's such a usual activity. Ideally what I'm looking for is a way to check if a

When using gets to get a file name in C, the file opens but when using fgets it does not

耗尽温柔 提交于 2020-01-10 05:34:04
问题 I'm trying, in C, to get a string from user input so the program can open a chosen file. I tried using fgets because I read on numerous threads that it is the safer option (as opposed to gets). However when a string is stored using gets, the file opens, but with fgets it does not. Here is the code I'm using: char csvFile[256]; FILE *inpfile; printf("Please enter CSV filename: "); fgets(csvFile,256,stdin); printf("\nFile is %s\n",csvFile); inpfile = fopen(csvFile,"r"); if(inpfile == NULL) {

stm32 zip gz zlib研究并移植

心已入冬 提交于 2020-01-10 04:56:52
今天,zlib是一种事实上的业界标准,以至于在标准文档中,zlib和DEFLATE常常互换使用。数以千计的应用程序直接或间接依靠zlib压缩函式库,包括: * Linux核心:使用zlib以实作网络协定的压缩、档案系统的压缩以及开机时 解压缩 自身的核心。 * libpng,用于PNG图形格式的一个实现,对bitmap数据规定了DEFLATE作为流压缩方法。 zlib库已经有人移植到RTT上了,并作为RTT的一个组件在可以在建工程的时候添加进去,我的硬件平台是STM32F437II,那个组件仅仅是移植了zlib库,并提供了一个例程,zlib_sample.c,这个例程很重要,我移植gzip zip的时候就是参考这个例程的,里面月很多系统调用,比如fopen(), 在RTT下没有,这是在stdio.h中声明的一个函数,但函数定义找不到,最终与RTT的接口在哪我也不知道,但是可以确实的是在RTT下此函数可以用, 还有很多类似的问题。 估计这个程序初衷就不是让单片机用的,里面充斥的大量的系统定义,类似 #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) #if defined(USE_FILE32API) #define fopen64 fopen #define ftello64 ftell

php 文件读取方式

我们两清 提交于 2020-01-10 04:53:32
整理了一下PHP中读取文件的几个方法,方便以后查阅。 1.fread    string fread ( int $handle , int $length )   fread() 从 handle 指向的文件中读取最多 length 个字节。该函数在读取完最多 length 个字节数,或到达 EOF 的时候,或(对于网络流)当一个包可用时,或(在打开用户空间流之后)已读取了 8192 个字节时就会停止读取文件,视乎先碰到哪种情况。   fread() 返回所读取的字符串,如果出错返回 FALSE。 <?php $filename = "/usr/local/something.txt"; $handle = fopen($filename, "r");//读取二进制文件时,需要将第二个参数设置成'rb' //通过filesize获得文件大小,将整个文件一下子读到一个字符串中 $contents = fread($handle, filesize ($filename)); fclose($handle); ?>   如果所要读取的文件不是本地普通文件,而是远程文件或者流文件,就不能用这种方法,因为,filesize不能获得这些文件的大小。此时,你需要通过feof()或者fread()的返回值判断是否已经读取到了文件的末尾。   例如: <?php $handle = fopen(

C read entire line of file [closed]

一世执手 提交于 2020-01-07 06:36:50
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I am trying to program a tool in C . Part of this program is to use a text file and read it line by line, while storing all lines into an array to have it available for future use. That's what I have so far: int main(){ FILE *fp = fopen("file.txt", "ab+"); if (fp == NULL) { printf("FILE ERROR"); return 1; } int

warning: fopen() call [duplicate]

可紊 提交于 2020-01-06 23:20:44
问题 This question already has answers here : Why am i getting this warning in “if (fd=fopen(fileName,”r“) == NULL)”? (6 answers) Closed last year . hi I'm programming with stdlib under linux. The gcc emits the following warning for the following line of code, any idea why is that? FILE *fd; if ( fd = fopen( filename, "rw" )== NULL ) { and the warning is: warning: assignment makes pointer from integer without a cast. How this can be happen , according to the stdlib documentation the return type of