title: PHP image upload and store the image name to MySQL table column script not working?
body: <p>The script is constructed like this:</p>
  
  <pre><code>// Function For Image Upload
  public function storeUploadedImage($image) {
      if ($image['error'] == UPLOAD_ERR_OK) {
          // Does the Document object have an ID?
          if (is_null($this-&gt;id))
              trigger_error("Document::storeUploadedImage(): Attempt to upload an image for an Document object that does not have its ID property set.", E_USER_ERROR);
          // Delete any previous image(s) for this Document
          $this-&gt;deleteImages();
          // Get and store the image filename extension
          $this-&gt;imgExtension = strtolower(strrchr($image['name'], '.'));
          // Store the image
          $tempFilename = trim($image['tmp_name']); 
          if (is_uploaded_file ($tempFilename)) {
          if (!(move_uploaded_file($tempFilename, $this-&gt;getImagePath())))
              trigger_error("Document::storeUploadedImage(): Couldn't move uploaded file.", E_USER_ERROR);
          if (!(chmod($this-&gt;getImagePath(), 0666)))
              trigger_error("Document::storeUploadedImage(): Couldn't set permissions on uploaded file.", E_USER_ERROR);}
          // Get the image size and type/Extension
          $attrs = getimagesize ($this-&gt;getImagePath());
          $imageWidth = $attrs[0];
          $imageHeight = $attrs[1];
          $imageType = $attrs[2];
          // Load the image into memory
          switch ($imageType) {
          case IMAGETYPE_GIF:
              $imageResource = imagecreatefromgif ($this-&gt;getImagePath());
              break;
          case IMAGETYPE_JPEG:
              $imageResource = imagecreatefromjpeg ($this-&gt;getImagePath());
              break;
          case IMAGETYPE_PNG:
              $imageResource = imagecreatefrompng ($this-&gt;getImagePath());
              break;
          default:
              trigger_error ("Document::storeUploadedImage(): Unhandled or unknown image type ($imageType)", E_USER_ERROR);
          }
          // Copy And Resize The Image To Create The Thumbnail
          $thumbHeight = intval ($imageHeight / $imageWidth * 120);
          $thumbResource = imagecreatetruecolor (120, $thumbHeight);
          imagecopyresampled($thumbResource, $imageResource, 0, 0, 0, 0, 120, $thumbHeight, $imageWidth, $imageHeight);
          // Save the Image thumbnail
          switch ($imageType) {
          case IMAGETYPE_GIF:
              imagegif ($thumbResource, $this-&gt;getImagePath("thumb"));
              break;
          case IMAGETYPE_JPEG:
              imagejpeg ($thumbResource, $this-&gt;getImagePath("thumb"), 85);
              break;
          case IMAGETYPE_PNG:
              imagepng ($thumbResource, $this-&gt;getImagePath("thumb"));
              break;
          default:
              trigger_error ("Document::storeUploadedImage(): Unhandled or unknown image type ($imageType)", E_USER_ERROR);
          }
          $this-&gt;update();
      }
  }
  // Funcion To Get The Relative Path To The Article's Fullsize Image
  public function getImagePath($type="fullsize") {
      return ($this-&gt;id &amp;&amp; $this-&gt;imgExtension) ? ("/images" . "/$type/" . $this-&gt;id . $this-&gt;imgExtension) : false;
  }
  </code></pre>
  
  <p>This is the form input field:</p>
  
  <pre><code> &lt;input type="file" name="image" id="image" placeholder="Choose an image to upload" maxlength="255"/&gt;
  </code></pre>
  
  <p>The rest of the inputs store to the MySQL database table. No error is showing for the upload. The image isn't uploading to the designated directory which is defined in a configuration file which is required in this script</p>