title: How to debug a PHP file that is being called by AJAX?
body: <p>I have a php file for uploading a picture (it uploads the picture, creates its thumbnail and also adds watermark to the picture). The file is being called by AJAX.</p>
  
  <p>It was working on on my localhost on Windows XP with WAMPSERVER 2.0. Now I have installed Windows Vista and suddenly it doesn't work properly (the picture gets uploaded but the thumbnail and watermark parts don't work).</p>
  
  <p>I'm using exactly the same software to test the application on my local machine (WAMPSERVER 2.0) yet it doesn't work.</p>
  
  <p>How to debug this file? Here's how it looks:</p>
  
  <pre><code>&lt;?php
  
  define('BASE_PATH', substr(dirname(dirname(__FILE__)), 0, -22));
  
  // set the include path
  set_include_path(BASE_PATH
                   . '/../../library'
                   . PATH_SEPARATOR
                   . BASE_PATH
                   . '/library'
                   . PATH_SEPARATOR
                   . get_include_path());
  
  // autoload classes from the library
  function __autoload($class) {
      include str_replace('_', '/', $class) . '.php';
  }
  
  $configuration = new Zend_Config_Ini(BASE_PATH
                                       . '/application'
                                       . '/configs/application.ini',
                                       'development');
  $dbAdapter = Zend_Db::factory($configuration-&gt;database);
  Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter);
  
  function _getTable($table)
  {
      include BASE_PATH
      . '/application/modules/default/models/'
      . $table
      . '.php';
      return new $table();
  }
  
  $albums = _getTable('Albums');
  $media = _getTable('Media');
  
  if (false === empty($_FILES)) {
  
      $tempFile = $_FILES['Filedata']['tmp_name'];
      $extension = end(explode('.', $_FILES['Filedata']['name']));
  
      // insert temporary row into the database
      $data = array();
      $data['type'] = 'photo';
      $data['type2'] = 'public';
      $data['status'] = 'temporary';
      $data['user_id'] = $_REQUEST['user_id'];
      $paths = $media-&gt;add($data, $extension, $dbAdapter);
  
      // save the photo
      move_uploaded_file($tempFile,
                         BASE_PATH . '/public/' . $paths[0]);
  
      // create a thumbnail
      include BASE_PATH . '/library/My/PHPThumbnailer/ThumbLib.inc.php';
      $thumb = PhpThumbFactory::create('/' . $paths[0]);
      $thumb-&gt;adaptiveResize(85, 85);
      $thumb-&gt;save(BASE_PATH . '/public/' . $paths[1]);
  
      // add watermark to the bottom right corner
      $pathToFullImage = BASE_PATH . '/public/' . $paths[0];
      $size = getimagesize($pathToFullImage);
      switch ($extension) {
          case 'gif':
              $im = imagecreatefromgif($pathToFullImage);
              break;
          case 'jpg':
              $im = imagecreatefromjpeg($pathToFullImage);
              break;
          case 'png':
              $im = imagecreatefrompng($pathToFullImage);
              break;
      }
      if (false !== $im) {
          $white = imagecolorallocate($im, 255, 255, 255);
          $font = BASE_PATH . '/public/fonts/arial.ttf';
          imagefttext($im,
                      13, // font size
                      0, // angle
                      $size[0] - 132, // x axis (top left is [0, 0])
                      $size[1] - 13, // y axis
                      $white,
                      $font,
                      'HunnyHive.com');
          switch ($extension) {
              case 'gif':
                  imagegif($im, $pathToFullImage);
                  break;
              case 'jpg':
                  imagejpeg($im, $pathToFullImage, 100);
                  break;
              case 'png':
                  imagepng($im, $pathToFullImage, 0);
                  break;
          }
          imagedestroy($im);
      }
  
      echo "1";
  
  }
  </code></pre>