The file function parses a text file into an array, and the file_get_contents function returns a text file as a string.
Tag Archives: file
How to open file links in Firefox 1.5 and above
Found some instructions about How to open file links in Firefox 1.5 and above and I’m going to try it out just as soon as I can reset my browser.
Basically you add something like the following to your user.js file which is in C:\Documents and Settings\[User Name]\Application Data\Mozilla\Firefox\Profiles\[Profile]\user.js.
user_pref("capability.policy.policynames", "localfilelinks"); user_pref("capability.policy.localfilelinks.sites", "http://www.example.com"); user_pref("capability.policy.localfilelinks.checkloaduri.enabled", "allAccess");
Internet explorer support for file URIs
The URI file://bender-xp/C$/ works in an anchor tag in IE8 to open the \\bender-xp\C$ file share on my network. In this case bender-xp was the name of my local machine but it works for remote file shares too (I tested it to a Samba share on another box).
Unfortunately my version of Firefox (version 9.0.1) doesn’t support this.
svn:ignore a file from the command line
I found Command Line svn:ignore a file while I was looking to do just that.
Using PHP output buffering to read a file
There’s a function in PHP called readfile which will read a file and send its contents to stdout. That can be handy, but it’s not much good to you if you want to read the content of the file into a string.
There’s a neat trick using PHP’s output buffering that enables you to read the content of a file into a string without printing anything on stdout, and it goes like this:
// start an output buffer ob_start(); // print the file to the output buffer readfile( $file_path ); // get the contents of the output buffer $content = ob_get_contents(); // cancel the output buffer ob_end_clean();
Writing a file in PHP
I found myself looking this up, I’ve probably done that before.
To write a file in PHP:
$path = './test.txt'; $file = fopen( $path, 'w' ); if ( ! $file ) { throw new Exception( "Cannot write '$file'." ); } fwrite( $file, "content\n" ); fclose( $file );
Bash aliases for listing hidden files
I finally figured out the ls command to list hidden files, and decided to setup a ~/.bash_aliases file for the first time. My ~/.bash_aliases file is now:
alias l.='ls -d .[!.]*' alias ll.='ll -d .[!.]*'
So I have an “l.” command which will list hidden files and directories, and an “ll.” command which will list the same information in detail.
Creating a temp file in bash
To create a new temporary file in bash use the mktemp command. E.g.:
path="$(mktemp)"
There’s a -d argument to mktemp that will make a temp directory.
Extracting a single file from a tar archive
You can use a parameter to the -x command line switch to tell the tar command that you just want to extract one particular file from the archive. For example:
$ tar -x filename/to/extract -f tarfile.tar
You can use the -O command line switch in conjunction with the above to have the file’s contents printed on stdout rather than created in the file system.
Setting modification time on files in Linux
If you want to change the modification time of a file on Linux, the command you’re looking for is touch. You can use touch with the -r parameter to specify a reference file who’s date and time information will be used as the basis for a new (or existing) file.