March 08, 2003 | Category:

PHP Challenge #3

As a result of some feedback, this challenge is going to be a bit more practical. The previous were practical in the sense that they could be used in some circumstances, but they had nothing to do with every day usage of PHP. This one does.

I want a function that takes in 3 variables:

  1. $Path: a directory path in the form “/path/to/folder”,
  2. $Filename: the name of some file (including extension, i.e. file.txt,
  3. $String: a string of characters

Now, the function must:

  • Create all directories in $Path that don’t already exist,
  • Create $Filename in the directory created by $Path,
  • Put the contents of $String into $Textfile

Please remember, I’ll be testing this on a Linux server so file permissions matter. You will almost certainly need the chmod() function.

The rules are:

  • The winner is the person who writes the most efficient script (i.e. the one whose script runs the fastest over several test runs). Size of the function is not an issue this time,
  • All functions should return a value of true if the operation is succesful, false otherwise,
  • All functions must be called FileCreator,
  • All functions submitted are considered public domain and hence can be reproduced and used with or without credit to anyone by anyone (so no bitching if someone rips off your script after the challenge finishes),
  • The winning script will be archived here for prosperity and to help others,
  • New rules may be added here at any time,
  • My decision is final,
  • All functions should be submitted to solitude@vkps.co.uk,
  • This is a slightly harder task, so the deadline is 12pm GMT on 19th March 2003

You have 11 days from now. Good luck!