/** * 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; }