kieranbarnes these are the things i learnt today

Read a file into an array

Posted on July 3, 2007

Here's something that puddled me for a while...

$filename = 'file.txt';
$file_handle = fopen($filename, 'r');
$data = '';
while(!feof($file_handle)){
$data .= fgets($file_handle, 1024);
}

Filed under: PHP No Comments

Converting XLS to CSV. Simple, eh? Well, sorta.

Posted on July 3, 2007

I hate problems that can be solved really easily. (With a totally different set of tools). I needed to open Excel (XLS) files in PHP. Simple enough you think, IF you are using Windows.

IF I was using Windows, I would have a bunch of options open to me, I could use PHP's COM & .NET functions. Or PHP's ODBC functions. Or a selection of classess from PHP Classes.

Filed under: Linux, PHP Continue reading

NTLM Authentication (Active Directory) on Apache (Linux)

Posted on July 3, 2007

Here is a quick guide to enabling NTLM authentication for Apache 2.
I generally use Ubuntu, so I am a heavy apt-get'er, but I prefer to build my apache from source.

Filed under: Linux Continue reading

Apache2 mod_deflate

Posted on July 3, 2007

The mod_deflate module provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network.

Lazy man's description, your pages load quicker.

Filed under: Linux Continue reading

Card Reader Annoyances

Posted on July 3, 2007

My new Dell computer came with one of those 1,600 in 1 internal memory card readers. The 1,600 drives in 'My Computer' really irritated me.

OK, so I exaggerated slightly. But the extra 3 drives did irritate me. My cameras use SD cards so I can safely disable the ones I don't use.

Apache, JungleDisk and Port 80

Posted on July 3, 2007

I was tearing what little hair I have trying to solve a very strange bug on Windows with Apache 2 & JungleDisk.
(Yes I use Amazon's Simple Storage Service for all my backups).

I was getting the following errors in Event Log, for what appeared to be no reason.

The Apache service named reported the following error:
>>> (OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_sock: could not bind to address 0.0.0.0:80 .

The Apache service named reported the following error:
>>> Unable to open logs

file_exists(), is_file() & is_dir() with spaces?

Posted on June 26, 2007

Why won't file_exists(), is_file(), is_dir() return true if the file or directory has a space in it?

I spent a few hours trying all kinds of ways to make this work. I finally settled on using $file->setName("safe"); from PEAR's HTTP_Upload class which makes the uploaded file "safe".

What's safe?

Filed under: PHP 1 Comment

Yellow text?

Posted on June 25, 2007

I stumbled over a strange bug on two systems the other day where the imagettftext() function was always writing the text in yellow. No matter how I set the colour, imagecolorallocate($image, 0, 0, 0);, I would always get yellow. Why yellow?

Both systems are Ubuntu, I don't know if it is a mix up on the libraries from the package, or indeed PHP.

I had to recompile PHP ignoring the --with-ttf option which most docs suggest, and just use the --with-freetype-dir instead. Problem solved.

Filed under: Linux, PHP No Comments

Unnamed Caterpillar

Posted on June 25, 2007

Nymphalis antiopa /Camberwell Beauty. Apparently.

dsc_1748-medium.JPG

Filed under: Photography No Comments

“Mail option not available!”

Posted on June 25, 2007

I spotted a strange PHP "feature" in the error_log() feature.

PHP checks for sendmail functionality once during ./configure for the mail() and error_log() functions.

Now, you can quite happily pass the sendmail path with the 'additional_parameters' flag to the mail() function, if you added mail support later but error_log() won't take that flag, so it fails with "Mail option not available!"

Rule: Install postfix/qmail/whatever BEFORE installing PHP if you want to use mail as an error_log() option.

Filed under: Linux, PHP No Comments