Beispiel #1
0
 public static function rmdir($dir)
 {
     PHPWS_File::appendSlash($dir);
     if (is_dir($dir)) {
         $handle = opendir($dir);
         while ($file = readdir($handle)) {
             if ($file == '.' || $file == '..') {
                 continue;
             } elseif (is_dir($dir . $file)) {
                 PHPWS_File::rmdir($dir . $file);
             } elseif (is_file($dir . $file)) {
                 $result = unlink($dir . $file);
                 if (!$result) {
                     PHPWS_Error::log(PHPWS_FILE_DELETE_DENIED, 'core', 'PHPWS_File::rmdir', $dir . $file);
                     return false;
                 }
             }
         }
         closedir($handle);
         $result = rmdir($dir);
         if (!$result) {
             PHPWS_Error::log(PHPWS_DIR_DELETE_DENIED, 'core', 'PHPWS_File::rmdir', $dir);
             return false;
         }
         return true;
     } else {
         return false;
     }
 }
Beispiel #2
0
 /**
  * The IXR library required a change to make this work.
  * If you update that file, make sure the base64 decode contains
  * a trim call on the currentTagContents variable.
  */
 public function metaWeblog_newMediaObject($args)
 {
     PHPWS_Core::requireInc('core', 'file_types.php');
     PHPWS_Core::initCoreClass('File.php');
     $allowed_images = unserialize(ALLOWED_IMAGE_TYPES);
     /* Login the user */
     $logged = $this->logUser($args[1], $args[2], 'media');
     if ($logged !== true) {
         return $logged;
     }
     $filename = PHPWS_File::nameToSafe($args[3]['name']);
     $filetype = $args[3]['type'];
     $ext = PHPWS_File::getFileExtension($filename);
     if (!(ALLOW_OCTET_STREAM && $filetype == 'application/octet-stream') && !in_array($filetype, $allowed_images)) {
         return new IXR_Error(-652, "File type '{$filetype}' not allowed.");
     }
     if (!isset($allowed_images[$ext])) {
         return new IXR_Error(-653, "File extension '{$ext}' not allowed.");
     }
     if (isset($this->image_directory)) {
         $img_directory =& $this->image_directory;
     } else {
         $img_directory = 'images/';
     }
     PHPWS_File::appendSlash($img_directory);
     $source_file = $img_directory . $filename;
     @unlink($source_file);
     $handle = @fopen($source_file, 'wb');
     if (!$handle) {
         return new IXR_Error(-2323, 'Unable to open file.');
     }
     $image = $args[3]['bits'];
     if (!@fwrite($handle, $image)) {
         return new IXR_Error(-651, "Unable to write file - {$filename}.");
     }
     fclose($handle);
     $url = PHPWS_Core::getHomeHttp() . $img_directory . $filename;
     return $url;
 }