File uploads are probably one of the things that new coders get worried about, and it is actually very simple. PHP has made vast inroads into supporting file uploads, and you can upload a file with just a few small lines of code.
In this article, I'm going to go through some simple things you should consider when uploading files, and some common mistakes made.
Uploading a file
Uploading a file is very easy. You need to add two things to your form. The first is to provide the correct enctype in the form tag, and the other is to have a file select input box:
Continue Reading April 5th, 2006
A friend brought to my attention that the php.net site was sporting a rather different design:

Seems someone forgot to make sure all the functions were included. The irony.
March 23rd, 2006
Its quite common these days to input one or more phone numbers. Be it home, work, fax or mobile, everyone's got a number, and you will invariably need to collect that piece of data some time soon.
Looking at some sites, its blatantly obvious that they do nothing to validate the data before it is entered into the database and when it is later retrieved, its printed out the same as it was input. A good thing would be to:
- Validate the incoming phone number. Make sure it has enough digits at a minimum
- Store the phone number in a format that is easily retrievable and searchable
- When displaying this phone number in the future, we should have a standardised pattern of display
March 11th, 2006
Zend Framework? Zend? Framework? Common questions to this posts title. First, lets set the landscape. To quote the Zend website:
Zend delivers the premier web application platform products and services for PHP applications.
Zend is the corporation most closely associated to PHP. You most likely haven't heard of Zend before, apart from the Zend Optimizer, but they are the company behind a lot of the driving force in pushing PHP into enterprise locations.
March 7th, 2006
During the life of a website, its quite common for pages to move around or to 're-structure' your site's files and folders. However, you can come across issues when people linking to your page go to their 'stale' bookmark of your site, and find that page is missing - in fact, they'll get a '404 Page Not Found'. The same will go for search engines like google and yahoo, and will adversely affect your rankings within their results.
So what do I do?
Continue Reading March 7th, 2006
It has become apparent that spammers are getting even smarter than we take them for. Rather than abuse open relays, which are almost non-existent, these scum-of-the-earth 'traders' are now abusing contact forms.
However, the problem isn't necessarily that they are attempting to use the contact forms. The problem that exists is that the average coder with little or no understanding of security issues can create a contact form for their website which can act as an open invitation to spammers.
The Problem
Lets take a quick look at a sample of code:
Continue Reading February 24th, 2006
Over time, there comes a point where you have to make certain choices as a DBA in order to maintain the integrity and efficiency of your database system. In a fair amount of systems, there is information that needs to be archived away, possibly compressed, and then used to do a few lookups on when needed.
In the past, you could compress MyISAM tables, however, this required you to take your MySQL server offline to perform the compression. However, starting with MySQL 4.1.3, there is the new ARCHIVE engine. You can find out if your MySQL distribution support the ARCHIVE format by running the following query:
February 16th, 2006
I recently heard about someone who used to store dates in their DB, retrieve them, and then use mktime(), date() etc to then use that date in a more readable format! So here's a quick look into some of the ways to retrieve dates from MySQL and format them.
Timestamps are your Friend
The UNIX timestamp is a count of the number of seconds since 1st January 1970. The date() function in PHP can format a UNIX timestamp into a large number of user-defineable formats:
Continue Reading February 13th, 2006
One of the talks whilst I was at the UK PHP Conference was on AJAX, and its downfalls. The talk was done by Harry Fuecks, someone whose opinion is respected within the online community. I've always been a bit wary of 'new' technologies when they surface, and the mad rush to implement them as they are 'cool'. Ajax is not exceptionally new. Internet Explorer was the first browser to implement the XMLHttpRequest protocol as an ActiveX object, way back in IE 5 circa 1999. However, its only been the recent use by certain big sites such a Google and Amazon that have made it more mainstream in the rush to implement it.
Continue Reading February 11th, 2006
A new feature of MySQL 5.1 is Events. Similar to a crontab or the 'Task Schedule', it allows you to execute an SQL statement at certain time intervals. The syntax is exceptionally easy to use:
CREATE EVENT [ IF NOT EXISTS ] event_name
ON SCHEDULE schedule
[ ON COMPLETION [ NOT ] PRESERVE ]
[ ENABLED | DISABLED ]
[ COMMENT 'comment' ]
DO sql_statement;
The first thought might be why you would want to run such a query from within MySQL. Running queries at regular intervals is sometimes necessary in large projects, e.g. for general cleanup etc. You can do this from within your chosen scripting language (PHP, Ruby etc), however, this creates another layer of dependancy. If your PHP script can't connect to the MySQL server, then it won't run - storing the event within MySQL overcomes this dependancy.
Continue Reading January 27th, 2006
Next Posts
Previous Posts