FAQ Database Discussion Community


Call a PHP from another PHP (without cURL)

php,json,curl,fopen
I have a HTML page that has to call a PHP on another domain. The "Same-Origin-Rule" of most browsers prohibits that call. So I want to call a PHP on my domain to call a PHP on the target domain. I want to avoid cURL so I decided to use...

can't create files in typo3 inside fileadmin

fopen,extbase,typo3-4.5
I am building an extension with extbase where I need to create a pdf file inside fileadmin folder with php from a controller : fopen("/fileadmin/pdf/anass.pdf", "w") or die('could not create file'); The permission is granted to write files ... so I think I made a mistake writing the path. Could...

Receiving error code during output redirection using execvp

c,exec,fopen,io-redirection,dup2
I am trying to redirect the output from ls to a file, in a shell I created in C. I type in: ls > junk and what I get out is: ls: cannot access >: No such file or directory Then if I use CTRL-D to exit the shell it...

Reading Text file in C, skip first line

c,file,line,fopen,skip
I have a big problem with my program. I would like to skip reading from 1st line and then start reading from others. I wasted so much time on searching it in the Internet. This is my txt file. LP bfdhfgd ffhf fhfhf hgf hgf hgf ffryt f uu 1...

C Segfault in readdir after chdir

c,fopen,readdir,chdir
I am having a weird issue with this C program I'm writing to loop through a directory and open each file to do some work on. My program is located in the parent directory of the directory I'm searching through. In order for fopen to be able to see the...

How can I most efficiently read the first n lines of a large text file in php?

php,fopen,fgets,fread,feof
So far I'm able to return the entire file, or an empty string. But not the first n lines of a file as expected. echo head('/path/to/my_file.txt',100); // returns '', or in other versions `1\n1\n...` function head($filepath, $lines = 1, $adaptive = true) { // Open file $f = @fopen($filepath, "rb");...

fwrite do not overwrite my .txt

php,fopen,fwrite
I have a button, I would like that when I press it, it writes on a text file its state and the button changes its value, like a toggle switch. <button type="button"><?php echo $button ?></button> My problem is, once I pressed it, the first value on the text file is...

Segmentation fault on fopen C [duplicate]

c,file,fopen
This question already has an answer here: When using gets to get a file name in C, the file opens but when using fgets it does not 3 answers guy's well I have this code #include <stdio.h> typedef struct { int numero, notaF, notaE; char nome[100]; } ALUNO; void...

using $_SERVER['DOCUMENT_ROOT'] with fopen() php [closed]

php,fopen
Background: I am using cPanel on my website and I have had problems with including files and such so I have gone to using $_SERVER['DOCUMENT_ROOT'] when doing includes. Now I am trying to do stuff with fopen() and I am not getting the right files. (Also note that the files...

Can we open a binary file in C without fopen?

c,binary,fopen
In C programming, can we open a binary file without fopen() , only with open ? Because I need a file descriptor, not a filestream. Thank you...

PHP: file_put_contents and writing to multiple files in a for loop not working

php,fopen,file-put-contents
For some background I have a bit of code that I am using to generate html files that contain a link to a unique code. Ultimately this ends up on a USB drive thats distributed to customers. This is done in batch so i can create as many custom files...

How to write an array as csv file content using php?

php,csv,fopen,fputcsv
I am importing a CSV file into my site which contain Hebrew language.While opening the CSV file in the notepad, the Hebrew language content are not enclosed by the quotes. The content which is not in quotes are not read in my site. During the time of uploading this csv...

How to open a text file from matlab to view?

matlab,fopen
I am having a text file and I want to view it through Matlab command instead of opening it through the file manager. I have tried the following: fid= fopen('exp.txt','r'); But its not opening. Any anyone help me with this? Thanks....

stat(), fstat(), lstat(), and fopen(); how to write TOCTOU protected system independent code

c,fopen,fstat
I've been dealing with a problem for a few weeks now updating 20 year code that needs to be system independent (work on both Linux and Windows). It involves Time-of-Check, Time-of-Use (TOCTOU) issues. I made a thread here, but it didn't go very far, and after ruminating on it for...

File I/O in C - How to read from a file and then write to it?

c,file-io,fopen,fgetc
I'm new to file i/o in C, and in my code I want to read information from a text file and then write to it. I tried to open a csv file using fopen("file.csv", "r+t") in order to be able to read and then write to the same file. So...

Finishing script/function execution when error occurs

matlab,error-handling,fopen
I'm using function that reads and process structured files: fname=strcat(folder,'\',fname); FID=fopen(fname); % reading lines and digging and procsesing data using fgetl() and regexp() fclose(FID); When there's any error in reading and digging part an error message is thrown but the file is opened and FID pointer is lost. Mostly it's...

Saving File to Folder using PHP

php,dictionary,fopen,tcpdf
Few examples I've tried // Worked fopen($OutputFolderPath."Text.pdf", "w"); // Didn't work $pdf->Output($OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . '_' . $Mother->PatientTableRecord['NHSID'] . ' ' . date('d_m_Y') . '.pdf','F'); // $OutputFolderPath . $Mother->PatientTableRecord['Forename'] . ' ' . $Mother->PatientTableRecord['Surname'] . ' ' . date('d_m_Y h_i_s', time()) . '.pdf','F' // Works...

Best way to store the first and second word of a text file into two arrays

c,arrays,char,fopen,fscanf
I'm making a code for a program. It would have three text files: -list1.txt having a column of words like: Cat Dog Fish Computers -change.txt having two columns of text like Dog Marbles Computers Store -list2.txt being empty The program would take list.txt, and store its words in the list2.txt,...

Fopen() return false

php,fopen
$mId = 36008; $path = "message/piece_jointe/$mId/test-fo.pdf"; $fp = fopen ($path, 'w+'); $fp return false. However when i omit $mid ih the path variable it works fine. Can anyone help me please....

How I can write a html code (templete) to a html file by php? [closed]

php,html,fopen,fwrite,fclose
How I can write html code (not executable) to a file by using php filesystems. For example I want to put my html page template which includes DOCTYPE, HEADER, BODY BLOCK, FOOTER etc.

get all image source from a website in php

php,image,domdocument,fopen,src
What I want to do is let the user type a url which has images such as https://www.flickr.com/search/?text=arushad%20ahmed , and get all the image source in the 'src' attribute and display it. The following approach didn't work: $file = fopen("https://www.flickr.com/search/?text=arushad%20ahmed", "r"); $doc = new DOMDocument(); $doc->loadHTML($file); $image = $doc->getElementsByTagName('img'); foreach...

fopen mode w+ and reading the file?

php,fopen,mode
I'm going through all the modes and trying to understand where can you apply some of them, and I stumbled upon w. Now I understand how that mode works, but what's the purpose of w+? Obviously if we use fopen right after opening the file, it won't work since the...

paths not working correctly with fopen/fwrite

php,fopen,fwrite
I think it is something simple that has to do with my paths, because when I just create the files in the current folder, everything works. That being said, I am pretty unfamiliar with fopen(), fwrite(), and fclose(). The errors I am getting are (I think once the first one...

Trying to create file in directory in C, but file is not being created

c,fopen
I have been searching for hours and hours now and cannot figure out why this is not working. I want to create a file in C, in a directory I created, but the file is not being created. Here is the relevant code pertaining to making the directory and creating...

file_get_contents not working for some domains

php,fopen,file-get-contents
As a part of the requirement I need to find out whether a domain is parked or not. As there is no efficient way to find out this, I'm going to check the DOM for phrases like "Buy this domain", "may be for sale".. etc. I found some parked domains...

C: issues with fscanf as while parameter

c,fopen
This program section is supposed to read in an unknown number of names and ID number's and compile them into a linked list. The names are arranged first, last the id (George Washington, 188867). I've narrowed the problem down to my fopen statement and I can't figure out whats causing...

PHP filter hashtags from string and write result back to file

php,filter,fopen,fwrite,word
I'm using fopen() and fwrite() to write some JSON content to a file. My question: Is there a way to filter the content and write only specific words to that file? E.g.: I retrive "I #love #love #love you so #much my dear #brother!" from the JSON file and I...

How to open a file with append mode only if it exist

c++,c,fopen
The function fopen("file-name",a); will return a pointer to the end of the file. If the file exist it is opened, otherwise a new file is created. Is it possible to use the append mode and open the file only if it already exist? (and return a NULL pointer otherwise). Thanks...

two programs accessing one file

xcode,fopen
New to this forum - looks great! I have some Processing code that periodically reads data wirelessly from remote devices and writes that data as bytes to a file, e.g. data.dat. I want to write an Objective C program on my Mac Mini using Xcode to read this file, parse...

Trying to use fopen and fprintf with matlab, only writing once

matlab,input,printf,fopen
I'm having trouble writing to a file here... I must be making a simple mistake but I can't find it. Anyways, here's the code: ages = 1; while (ages > 0) fileID = fopen('age.txt', 'w'); %opens file ages = input('Enter an age (negative to quit): '); %user input if(ages >...

Shuffle and Display the Contents of .txt File

php,file,fopen
I am trying to read, shuffle, then display the contents of a text file. The text file contains a list of codes (each one on a new line - no commas etc). 1490 1491 1727 364 466 //... 783 784 786 My code: $file = fopen("keywords.txt", "r"); shuffle($file); while (!feof($file))...

PHP file opening error

php,file,fopen
Ok, so I have looked everywhere for an answer to this question and can not find it. So I have a php file on my godaddy website. The second I add this line of code to it: $myfile = fopen("fileName.txt", "r") or die("Unable to open file!"); It prints out this...

How to know if there is an error when attempting to open a file (when using fopen in C)

c,file,for-loop,fopen
I am opening multiple files in a while loop using fopen in C and want to be able to check if any of them will return an error. Relevant code: int i; for(i=0; i<10; i++) { file=fopen(myList[i], "r"); } How will I know if the file I'm currently looking at...

Image gets corrupted when copied using custom Python code

python,fopen
Here is the code def main(): f = open("image.jpg", "rb") filedata = f.read() f.close() print "Creating Test Image" f = open("ftp_test.jpg", "w+") f.write(filedata) f.close() print "Done!" if __name__ == '__main__': main() Im not sure, why but here is the original image and here is the resulting picture from the code...

php fgets explode shows “Array.” instead of $array [duplicate]

php,arrays,fopen,explode
This question already has an answer here: How to echo out the values of this array? 4 answers I am trying to convert a plain text logfile (no wordwrap) into something more readable. php-file <?php $log = fopen("/home/raspi/scripts/logs/test.log", "r"); while (!feof($log)){ $arrM = explode("|",fgets($log)); echo "$arrM . <br>"; }...

Read the file error C_language

c,file,fopen
i am trying to create file and write some data on it, but when i run the following code program runs to error: Error 1 error C2664: 'errno_t fopen_s(FILE **,const char *,const char *)' : cannot convert argument 1 from 'FILE *' to 'FILE **' #include "stdafx.h" #include <stdio.h> #include...

Read lines from file not return all

c,fopen,readfile,fgets
I'm trying to keep the words from a file into an array but I only read the first 8. My code below. #define BUF 128 /* can change the buffer size as well */ char ** readFileContentArray(char* filename){ int lines = 128; char ** strLines = (char **)malloc(sizeof(char*)*lines); FILE *plist...

fopen() works, dio_open() doesn't?

php,file,fopen
Seeing some issues running fopen() when dio_open() is working just fine. Here's a test script I wrote to check the issue as it was appearing in a new installation I'm trying to get working. <?php echo "Current User: " . get_current_user() . "<br/>"; echo "UID: " . getmyuid() . "<br/>";...

Ignoring return value of fscanf and Segmentation fault

c,segmentation-fault,fopen,compiler-warnings,fscanf
I was wondering how to solve a Core dumped issue on my C code. When I compile it with: g++ -g MatSim.cpp -o MatSim -lstdc++ -O3, I get three warnings, this is one (The other two are similar and are only differentiated by the string variable name): MatSim.cpp: In function...

Converting binary serialization to human-readable serialization

c,printf,fopen,fread,fscanf
I'm converting a program that used to do a binary dump of a struct to file and read that binary struct back in using fread. I want to convert it to creating and reading human readable data files, which of course means I need to format the data and such....

fopen and 'a+' mode in php?

php,pointers,fopen
Consider the code below (file test.txt doesn't exist): $fp = fopen('test.txt', 'a+'); echo ftell($fp); // 0 fwrite($fp, "abc\n"); fclose($fp); I run the code once - echo ftell($fp); // 0, I run the code again - echo ftell($fp); // 0 still returns 0. The file now contains abc\nabc\n, so I would...

Matlab Crahes upon fopen in Mex File

c,matlab,fopen,mex
I have a little experience with Matlab, but am new to the mex environment. What I am trying to do is to save some values I compute to a txt file in my C routine. For the sake of simplicity I am using the example arrayProduct.c from MathWork's Create C...

Should I fclose(file) if an error occured?

c,file,file-io,fopen,fclose
Code: FILE *fp = fopen(filename, "r"); if (!fp) { fprintf(stderr, "Failed to open a file\n"); // fclose(fp) <-- should I close file here? exit(1); } // Some operations on the file. fclose(fp); Question: If fopen() fails to open a file, should I still call fclose()?...

cURL headers in command line show content-type as image/png, in PHP shows text/html?

php,curl,fopen,fwrite
I'm attempting to use cURL to download an external image file. When used from the command line, cURL correctly states the response headers with content-type=image/png. When I attempt to use cURL in PHP however, it returns content-type=text/html. When attempting to save the file using cURL in PHP, with the CURLOPT_BINARYTRANSFER...