fopen

How to open a file and remove the last line?

I am looking to open up a file, grab the last line in the file where the line = "?>", which is the closing tag for a php document. Than I am wanting to append data into it and add back in the "?>" to the very last line. I've been trying a few approaches, but I'm not having any luck. Here's what I got so far, as I am reading from a zip...

How to open a file with UNICODE filename on Windows?

There is a 3rd lib only accept char* filename e.g. 3rdlib_func_name(char* file_name). Every things get wrong when I provide a filename in Chinese or Japanese. Is there any way to make this lib open UNICODE filename? The program is running on Windows. Thanks for your reply. ...

Do I use fopen or curl to load an XML file given a URL in PHP

I have an XML file I can get via a URL. I know I can get the file using fopen, but sometimes I've seen scripts use curl. Is there an advantage to using curl over fopen to get XML files? ...

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

The current content of this google docs page is: However, when reading this page with the following PHP fopen() script, I get an older, cached version: 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 d...

C - Opening a file inside a function using fopen

I am using Visual Studio 2005 (C\C++). I am passing a string into a function as a char array. I want to open the file passed in as a parameter and use it. I know my code works to an extent, because if I hardcode the filename as the first parameter it works perfectly. I do notice if I look at the value as a watch, the value includes the...

Write binary stream to browser using PHP

Background Trying to stream a PDF report written using iReport through PHP to the browser. The general problem is: how do you write binary data to the browser using PHP? Working Code header('Cache-Control: no-cache private'); header('Content-Description: File Transfer'); header('Content-Disposition: attachment, filename=climate-report...

PHP create huge errors file on my server feof() fread()

I have a script that allows users to 'save as' a pdf, this is the script - <?php header("Content-Type: application/octet-stream"); $file = $_GET["file"] .".pdf"; header("Content-Disposition: attachment; filename=" . urlencode($file)); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"...

Creating new folders if they don't exist for fopen

I have a C++ program that takes user input for fopen in order to initiate a file write. Could someone help me find a function which will return a FILE* and use the Windows specific version of mkdir in order to create the folder structure for fopen to never fail to open a new file in the specified location because one of the folders does ...

fopen won't open files across network

I can use fopen to open local files but can't open files across network on a different machine. I can map the drives and look at the files but can't open them using fopen. ...

how to get contents of site use HTTPS

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 = f...

How to read an word document in matlab

Can we read an word document(.doc) by an command fopen in matlab 6.1? If No please provide some information about the same. ...

[php] how to read only 5 last line of the txt file

hello i have a file named "file.txt" it updates by adding lines to it. I am reading it by this code: $fp = fopen("file.txt", "r"); $data = ""; while(!feof($fp)) { $data .= fgets($fp, 4096); } echo $data; and a huge number of lines appears. I just want to echo the last 5 lines of the file how can i do that ? thanks in advanced ...

PHP New Line will not work

Hi I am trying to create some code that first reads the existing contents of the file in and then adds the new line of code on a new line but the code i am using just adds it on the new text on to the already existing line instead of the new line... Here is the code i am using: <?php $id = $_GET['id']; $userfile = "user1.txt"; $fo = ...

In Windows, should I use CreateFile or fopen, portability aside?

What are the differences, and in what cases one or the other would prove superior in some way? ...

What's the best way to write to more files than the kernel allows open at a time?

I have a very large binary file and I need to create separate files based on the id within the input file. There are 146 output files and I am using cstdlib and fopen and fwrite. FOPEN_MAX is 20, so I can't keep all 146 output files open at the same time. I also want to minimize the number of times I open and close an output file. How ...

Writing a new line to file in PHP

My code: $i = 0; $file = fopen('ids.txt', 'w'); foreach ($gemList as $gem) { fwrite($file, $gem->getAttribute('id') . '\n'); $gemIDs[$i] = $gem->getAttribute('id'); $i++; } fclose($file); For some reason, it's writing \n as a string, so the file looks like this: 40119\n40122\n40120\n42155\n36925\n45881\n42145\n45880 Fro...

PHP - Shortcomings of fwrite?

I am working on a file-handler class and am running into some issues with file streams. Providing functionality for operations such as append and overwrite are a simple matter of changing the mode passed to fopen. However, providing an easy way to insert, update, and delete is proving to be more challenging. Pretty much, all the probl...

Creating an installer script

Hi all, I'm trying to create an installer, using a combination of fwrite and forms. Here's my code: <?php $myFile = "db_config.php"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, "$host = " . $_POST['host'] . ";\n $username = " . $_POST['username'] . ";\n $password = " . $_POST['password'] . ";\n $name = " . $_POS...

How can I alter a file and write only the changes to disk - basically, sed (python)?

Let's say I have a file /etc/conf1 it's contents are along the lines of option = banana name = monkey operation = eat and let's say I want to replace "monkey" with "ostrich". How can I do that without reading the file to memory, altering it and then just writing it all back? Basically, how can I modify the file "in place"? ...

fopen problem - too many open files

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 WinD...