fopen

how to get contents of site use HTTPS

你说的曾经没有我的故事 提交于 2019-12-31 02:28:06
问题 ex of site using ssl ( HTTPs ) : https://www.eb2a.com 1 - i tried to get its content using file_get_contents, but not work and give error ex : <?php $contents = file_get_contents("https://www.eb2a.com/"); echo $contents; ?> 2 - i tried to use fopen, but not work and give error ex: <?php $url = 'https://www.eb2a.com/'; $contents = fopen($url, 'r'); echo "$contents"; ?> 3 - i tried to use CURL, but not work and give BLANK PAGE ex : function cURL($url, $ref, $header, $cookie, $p){ $ch = curl

Write a CSV file from a PHP Array

喜夏-厌秋 提交于 2019-12-31 01:40:14
问题 I appreciate there are already a lot of questions around this subject. But, as I'm not a PHP developer, I'm struggling to get anything to work for my specific object structure. I have a pretty flat JSON structure that is being read into PHP just fine. All I need to do is go through the array of objects, create the CSV headings from the keys in the first object (they are all the same), and then write each line of the CSV using all the object properties. Here's a look at my PHP data: Array ( [0

filemtime returns same value before and after modification of file

北慕城南 提交于 2019-12-31 00:58:11
问题 Im trying to get the last modified time of a file before and after i write to it using fwrite. But, i get the same values for some reason. <?php $i = filemtime('log.txt'); echo gmdate("h:i:s", $i); echo "<br/>"; $e=fopen('log.txt', 'w'); fwrite($e, "well well well"); $j = filemtime('log.txt'); echo gmdate("h:i:s", $j); ?> Now i modify 'log.txt' with a text editor about a minute before i run this script. So i should be getting about 40-60 seconds of time difference. If someone could point out

Error handling in file opening

旧街凉风 提交于 2019-12-30 18:30:08
问题 [Question 1] When I open a file into a function, generally I do something like this: int read_file (char *filename) { FILE *fin; if ( !(fin = fopen(filename, "r")) ) return 1; /* ... */ return fclose(fin); } int main () { char filename[100]; if ( read_file(filename) ) { perror(filename); exit(1); } return 0; } Generally 0 return value is for errors (right?) then I can change the previous code into: int read_file (char *filename) { FILE *fin; if ( !(fin = fopen(filename, "r")) ) return 0; /* .

PHP output to file for download without creating file on the server

大憨熊 提交于 2019-12-30 11:13:12
问题 I would like to output my data to a file for the user to download without actually creating the file physically on the server. The data of the file is simply array that I'm converting into a CSV format for the user to download. Here's my code: $fh = fopen('file.csv','w'); fputcsv($fh,$arr); // $arr is my array that contains the data to be parsed into CSV fclose($out); The above code creates the file successfully... but I don't want to have to create a file. I want to simply stream the output.

Segmentation fault in C in K&R fopen and fillbuf

喜欢而已 提交于 2019-12-30 11:00:20
问题 I'm quite new to C. I faced a problem while studying the last chapter of K&R. I'm trying to implement fopen() and fillbuf() function by using system calls, open and read . I exactly copied the source code from the book but repeatedly get segmentation error after I compile. fp->fd = fd; fp->cnt = 0; fp->base = NULL; fp->flag = (*mode=='r')? _READ : _WRITE; Why does error occur? Here is my complete code. #include<fcntl.h> #include<unistd.h> #include<stdlib.h> #define PERM 0644 #define EOF (-1)

Segmentation fault in C in K&R fopen and fillbuf

我只是一个虾纸丫 提交于 2019-12-30 11:00:09
问题 I'm quite new to C. I faced a problem while studying the last chapter of K&R. I'm trying to implement fopen() and fillbuf() function by using system calls, open and read . I exactly copied the source code from the book but repeatedly get segmentation error after I compile. fp->fd = fd; fp->cnt = 0; fp->base = NULL; fp->flag = (*mode=='r')? _READ : _WRITE; Why does error occur? Here is my complete code. #include<fcntl.h> #include<unistd.h> #include<stdlib.h> #define PERM 0644 #define EOF (-1)

Is there a standard way to do an fopen with a unicode string file path?

我与影子孤独终老i 提交于 2019-12-30 07:58:09
问题 Is there a standard way to do an fopen with a unicode string file path? 回答1: In *nix, you simply use the standard fopen (see more information in reply from TokeMacGuy, or in this forum) In windows, you can use _wfopen, and then pass a unicode string (for more information, see MSDN). As there is no real common way, I would wrap this call in a macro, together with all other system-dependent functions. 回答2: No, there's no standard way. There are some differences between operating systems. Here's

Detailed error on fopen

血红的双手。 提交于 2019-12-30 05:37:05
问题 I'm using fopen to read from a file $fh = fopen($path, 'r') or die('Could not open file'); Now I contantly get error Could not open file. I checked the file path and even changed the permissions of the file to 777. Is there a way I can get a detailed error report as why the file can't be opened similar to mysql_error()? 回答1: Turn on error reporting, or, in a production environment (from PHP 5.2.0 onwards) you should also be able to use error_get_last(). 回答2: For php versions prior to 5.2

C print file path from FILE*

被刻印的时光 ゝ 提交于 2019-12-29 08:51:46
问题 FILE * fd = fopen ("/tmp/12345","wb"); If I have the variable fd , how can I print the file path ? (/tmp/12345) in Linux env. 回答1: There's no standard way to retrieve a pathname from a FILE * object, mainly because you can have streams that aren't associated with a named file ( stdin , stdout , stderr , pipes, etc.). Individual platforms may supply utilities to retrieve a path from a stream, but you'd have to check the documentation for that platform. Otherwise, you're expected to keep track