Image upload problems in PHP

I recently designed several web-based software applications  using PHP & MySQL.  Some of the applications allow the user to upload photographs to the web server.  However, it seems many times when I install one of these apps on a new server, I have trouble with the image upload feature.  After several episodes of head-scratching, I’m posting everything I know about the subject here.  Hopefully, it will server as a reminder to me and some assistance to others.

Most of the Linux servers I maintain are running Ubuntu 8.04, so the specific file locations will be geared toward that distribution.

  1. Make sure the php5-gd package is installed. That’s pretty basic but can be overlooked(I’m living proof of that). In Ubuntu 8.04 the command to install the appropriate package is:
    sudo apt-get install php5-gd
  2. In php.ini (usually in /etc/php5/apache2 or somewhere close), check the following values:
    memory_limit needs to be of sufficient size.
    post_max_size needs to be of sufficient size.
    file_uploads needs to be on
    upload_max_filesize needs to be of sufficient size
  3. Make sure the default system temp directory (usually /tmp) is writable by everybody.  This is usually the case by default, but I had this trouble on some physical servers that I had converted to OpenVZ containers.

Good luck! 🙂