function actionAdd()
 {
     // We return to the default action
     $action = 'default';
     // Process the form
     if ($this->form->validate()) {
         // Move the uploaded file
         $file = $this->form->getElement('image');
         if ($file->isUploaded()) {
             // Get the new filename
             $filename = YDStringUtil::stripSpecialCharacters($file->getBaseName());
             // Move the upload
             $file->moveUpload($this->dir_rel, $filename);
             // Check if it's an image
             $fileObj = new YDFSFile($this->dir_rel . $file->getBaseName());
             if (!$fileObj->isImage()) {
                 @unlink($this->dir_rel . $file->getBaseName());
             }
             // Create the thumbnails
             $thumb = new YDFSImage($this->dir_rel . $file->getBaseName());
             $thumb->_createThumbnail(100, 100, true);
             $thumb->_createThumbnail(48, 48, true);
         }
         // Get the name of the action
         $action = $this->form->getValue('action');
     }
     // Redirect to the list view
     $destination = YD_SELF_SCRIPT . '?do=' . $action;
     if (isset($_GET['field'])) {
         $destination .= '&field=' . $_GET['field'];
     }
     $this->redirect($destination);
 }
 function actionAdd()
 {
     // We return to the default action
     $action = 'default';
     // Process the form
     if ($this->form->validate()) {
         // Move the uploaded file
         $file = $this->form->getElement('image');
         if ($file->isUploaded()) {
             // Get the new filename
             $filename = YDStringUtil::stripSpecialCharacters($file->getBaseName());
             // Move the upload
             if (!is_dir($this->dir_rel)) {
                 @mkdir($this->dir_rel);
             }
             $file->moveUpload($this->dir_rel, $filename);
             // Check if it's an image
             $fileObj = new YDFSFile($this->dir_rel . $file->getBaseName());
             if (!$fileObj->isImage()) {
                 @unlink($this->dir_rel . $file->getBaseName());
             }
             // Delete the thumbnails
             @unlink($this->dir_rel . 's_' . $file->getBaseName());
             @unlink($this->dir_rel . 'm_' . $file->getBaseName());
         }
     }
     // Redirect to the list view
     $this->redirect(YD_SELF_SCRIPT . '?id=' . $this->item['id']);
 }
 function actionAdd()
 {
     // We return to the default action
     $action = 'default';
     // Process the form
     if ($this->form->validate()) {
         // Move the uploaded file
         $file = $this->form->getElement('image');
         if ($file->isUploaded()) {
             // Get the new filename
             $filename = YDStringUtil::stripSpecialCharacters($file->getBaseName());
             // Move the upload
             if (!is_dir($this->dir_rel)) {
                 @mkdir($this->dir_rel);
             }
             @$file->moveUpload($this->dir_rel, $filename);
             // Convert it to an object
             $fileObj = new YDFSFile($this->dir_rel . $file->getBaseName());
             // Check if it's a ZIP file
             if (strtolower($fileObj->getExtension() == 'zip')) {
                 // Include the unzip library
                 include YD_DIR_HOME . '/3rdparty/zip/unzip.lib.php';
                 // Convert it to a ZIP object
                 $zip = new SimpleUnzip($fileObj->getAbsolutePath());
                 // Get the directory as a path
                 $dir = new YDFSDirectory($this->dir_rel);
                 // Extract the images
                 foreach ($zip->Entries as $entry) {
                     // Save it as a filee
                     $entryFile = $dir->createFile($entry->Name, $entry->Data);
                     // Delete it if it's not an image
                     if (!$entryFile->isImage()) {
                         @unlink($entryFile->getAbsolutePath());
                     } else {
                         $entryFile = $this->weblog->resizeUploadedImage($entryFile);
                     }
                 }
             }
             // Check if it's an image
             if (!$fileObj->isImage()) {
                 @unlink($fileObj->getAbsolutePath());
             } else {
                 $fileObj = $this->weblog->resizeUploadedImage($fileObj);
             }
             // Delete the thumbnails
             @unlink($this->dir_rel . 's_' . $file->getBaseName());
             @unlink($this->dir_rel . 'm_' . $file->getBaseName());
         }
     }
     // Redirect to the list view
     $this->redirect(YD_SELF_SCRIPT . '?id=' . $this->item['id']);
 }
 /**
  *	This function will create a new file in the current directory, and will write the specified contents to the
  *	file. Once finished, it will return a new YDFSFile object pointing to the file. All directory paths are 
  *	relative to the current directory.
  *
  *	@param $filename	The filename of the new file.
  *	@param $contents	The contents of the new file.
  *
  *	@returns	YDFSFile or YDFSImage object pointing to the new file.
  */
 function createFile($filename, $contents)
 {
     // Set the directory of this object as the working directory
     chdir($this->getPath());
     // Create the new file
     $fp = fopen($filename, 'wb');
     // Save the contents to the file
     $result = fwrite($fp, $contents);
     // Check for errors
     if ($result == false) {
         trigger_error('Failed writing to the file "' . $file . '" in the directory called "' . $this->getPath() . '".', YD_ERROR);
     }
     // Close the file
     fclose($fp);
     // Create the YDFSFile object
     $obj = new YDFSFile($filename);
     // Check if it's an image
     if ($obj->isImage()) {
         $obj = new YDFSImage($filename);
     }
     // Return the file object
     return $obj;
 }