Drupal file_copy won't work outside of the Drupal instal

The selected file could not be uploaded, because the destination is not properly configured

This "feature" has bitten me before. It's one of those annoying Drupal things which would be fine if the error message wasn't so misleading.

What's happening is that file_copy() calls file_create_path()

<?php
function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
 
$dest = file_create_path($dest);
?>

While file_copy() doesn't declare that it only works in the Drupal folders - file_create_path is clear about this.

Read more

Eclipse PDT and Subversion

Version conflicts to be aware of

Ubuntu 8.10 (Intrepid Ibex) now ships with Subversion 1.5 

You can't use a svn 1.4 client and a svn 1.5 client on the same working copy.

While the subversion integration in Eclipse is great I still prefer to do some things on the command line and some with kdesvn.

Then you need to upgrade your subclipse plugin to subclipse 1.4

If you can - then upgrade to Eclipse 3.4 

Read more

Install runkit for unit testing

Unit testing Drupal can be pretty challenging as it's hard to isolate parts of the code.

It seems :

Read more

Drupal Object Orientation

One of the surprising things about Drupal is that it doesn't use object oriented coding.

There's a good page in the Drupal documentation about this

http://api.drupal.org/api/file/developer/topics/oop.html

It makes a good case for the design of Drupal, and goes a long way to explain why Drupal feels more OO than the code looks at first glance.

There has been discussion on the mailing list

Read more

Eclipse 3.4 (Ganymede) First Impressions

Well the new version of Eclipse (3.4 or Ganymede) is out and I've been trying it out. So far I've just installed it, adding in the components I want; and generally trying to see what's new.

 

Eclipse Splash Screen

Installation

I'm running Linux (Ubuntu 8.04) 

Read more

SimpleTest - expecting Exceptions

SimpleTest is a great testing framework for PHP, with a Drupal module available too.

Many tests are based on assert statements, but this patterns doesn't work for functions which are expected to throw Exceptions.

In that case the following pattern is often useful.

<?php

try {
 
foo($bar);
 
pass('Foo Bar worked');
} catch (
MyException $e) {
 
$this->fail($e->getMessage());
}
?>

Read more

How to enter a multibyte Unicode string in PHP

This has just taken me a suprisingly long time to work out ...

I needed to output a file with the follwing as a marker in various places.

Read more

Reading a unicode Excel file in PHP

It's easy to save an Excel file as CSV and read it in PHP with the fgetcsv function but this may not work so well if the file contains non-English characters.

Excel uses a non-standard character encoding for csv files.

You can save an Excel file as 'unicode' text however there are several unicode systems - Windows uses UTF-16, and PHP uses UTF-8.

To open the 'unicode text' file in PHP you have to convert it, in addition you may want to be able to open UTF-8 files that may be created by other systems.

Read more

Doc-comments and auto-completion in Eclipse

Using doc-comments in Eclipse really helps productivity by providing lots of tool-tip help and auto completion.

A colleague recently pointed out that Eclipse can auto-complete object properties (as long as you use the @property tag). I've found this really helpful and have been creating objects to return pass around - and found it a vwery neat way of working.

Read more

Project: Ramblers' Walks Finder

This project lists walks organised by Ramblers' groups nationwide and is kept updated by volunteers who plan, check and lead the walks

walks finder screenshot

The project aim was to make the website open to participation by hundreds of volunteers (without technical expertise) and to publicise activities to potential new members.

Read more