/**
  *  This function will move the uploaded file to the specified directory.
  *
  *  @param $dir (optional) The directory to move the file to. Defaults to the current directory.
  *  @param $fname (optional) File name to use. Prevents e.g. the file hits the FS with unwanted chars in it
  *  @param $retainExt (optional) Retain file name extension or not
  *  @returns  Boolean indicating if the move was succesful or not.
  */
 function moveUpload($dir = '.', $fname = '', $retainExt = false)
 {
     if (filesize($_FILES[$this->_form . '_' . $this->_name]['tmp_name']) == 0) {
         return false;
     }
     // Fetch extension if it is to be retained, set empty if otherwise
     $retainExt and $ext = '.' . YDPath::getExtension($_FILES[$this->_form . '_' . $this->_name]['name']) or $ext = '';
     // Create (new) file name
     $fname = $fname == '' ? $_FILES[$this->_form . '_' . $this->_name]['name'] : $fname . $ext;
     // Compile path
     $path = realpath($dir) . '/' . $fname;
     // Move file to temp location
     // plz point out in the docs this dir is _temporary_, as it is automatically made 0777!
     $result = move_uploaded_file($_FILES[$this->_form . '_' . $this->_name]['tmp_name'], $path);
     @chmod(realpath($dir), 0700);
     @chmod($path, 0700);
     // Provide an interface to some more useful information on the file
     $this->fileo = new YDFSFile($path);
     return $result;
 }
 function actionDefault()
 {
     YDDebugUtil::dump(YDPath::getDirectorySeparator(), 'getDirectorySeparator()');
     YDDebugUtil::dump(YDPath::getPathSeparator(), 'getPathSeparator()');
     YDDebugUtil::dump(YDPath::getVolumeSeparator(), 'getVolumeSeparator()');
     YDDebugUtil::dump(YDPath::changeExtension(__FILE__, '.tpl'), 'changeExtension( __FILE__, ".tpl" )');
     YDDebugUtil::dump(YDPath::getDirectoryName(__FILE__), 'getDirectoryName( __FILE__ )');
     YDDebugUtil::dump(YDPath::getExtension(__FILE__), 'getExtension( __FILE__ )');
     YDDebugUtil::dump(YDPath::getFileName(__FILE__), 'getFileName( __FILE__ )');
     YDDebugUtil::dump(YDPath::getFileNameWithoutExtension(__FILE__), 'getFileNameWithoutExtension( __FILE__ )');
     YDDebugUtil::dump(YDPath::getFilePath(__FILE__), 'getFilePath( __FILE__ )');
     YDDebugUtil::dump(YDPath::getFilePathWithoutExtension(__FILE__), 'getFilePathWithoutExtension( __FILE__ )');
     YDDebugUtil::dump(YDPath::getFullPath(__FILE__), 'getFullPath( __FILE__ )');
     YDDebugUtil::dump(YDPath::getTempFileName(), 'getTempFileName()');
     YDDebugUtil::dump(YDPath::getTempPath(), 'getTempPath()');
     YDDebugUtil::dump(YDPath::hasExtension(__FILE__), 'hasExtension( __FILE__ )');
     YDDebugUtil::dump(YDPath::hasExtension(YDPath::getFileNameWithoutExtension(__FILE__)), 'hasExtension( YDPath::getFileNameWithoutExtension( __FILE__ ) )');
     YDDebugUtil::dump(YDPath::isAbsolute(__FILE__), 'isAbsolute( __FILE__ )');
     YDDebugUtil::dump(YDPath::isAbsolute(YDPath::getFileName(__FILE__)), 'isAbsolute( getFileName( __FILE__ ) )');
     YDDebugUtil::dump(YDPath::join(__FILE__), 'join( __FILE__ )');
     YDDebugUtil::dump(YDPath::join(YDPath::getTempPath(), YDPath::getFileName(__FILE__)), 'join( getTempPath(), getFileName( __FILE__ ) )');
     YDDebugUtil::dump(YDPath::join(YDPath::getTempPath(), __FILE__), 'join( getTempPath(), __FILE__ )');
 }
 /**
  *	This rule checks if a file upload has the right file extension (case insensitive). 
  *
  *	@param $val			The value to test.
  *	@param $opts		The file extension it should match (can also be an array of extensions).
  *	@param $formelement	(not required)
  */
 function extension($val, $opts, $formelement = null)
 {
     include_once YD_DIR_HOME_CLS . '/YDFileSystem.php';
     if (!is_array($opts)) {
         $opts = array($opts);
     }
     $ext = YDPath::getExtension($val['name']);
     return YDValidateRules::i_in_array($ext, $opts);
 }
 /**
  *	Function to get the extension of the file.
  *
  *	@returns	String containing the extension of the file.
  */
 function getExtension()
 {
     return YDPath::getExtension($this->getAbsolutePath());
 }
 /**
  *	This rule checks if a file upload has the right file extension.
  *
  *	@param $val		The value to test.
  *	@param $opts	The file extension it should match (can also be an array of extensions).
  */
 function extension($val, $opts)
 {
     include_once dirname(__FILE__) . '/YDFileSystem.php';
     if (!is_array($opts)) {
         $opts = array($opts);
     }
     $ext = YDPath::getExtension($val['name']);
     return in_array($ext, $opts);
 }
 /**
  *	This function will get the name of the template.
  *
  *	@internal
  */
 function _getTemplateName($file = '')
 {
     if (file_exists($file)) {
         if ('.' . YDPath::getExtension($file) != YD_TPL_EXT) {
             trigger_error('The specified file ' . $file . ' is not a valid template file (wrong file extension)', YD_ERROR);
         }
         return realpath($file);
     }
     $this->template_dir = YDPath::getFullPath($this->template_dir);
     if (empty($file)) {
         $file = YDPath::getFileNameWithoutExtension(YD_SELF_FILE);
     }
     if (is_file(YDPath::join($this->template_dir, $file . YD_TPL_EXT))) {
         $tplName = $file . YD_TPL_EXT;
     } else {
         $tplName = $file;
     }
     if (!is_file(YDPath::join($this->template_dir, $tplName))) {
         trigger_error('Template not found: ' . $tplName, YD_ERROR);
     }
     return $tplName;
 }