Location: PHPKode > projects > DIY Blog > diy-blog/classes/diy-blog/model/AdminFilesResource.php
<?php

require_once 'diy-blog/model/BackEndResource.php';

require_once 'diy-blog/model/om/BaseBackEndResource.php';

/**
 * Backend Resource for uploading files.
 * Originally generated by Propel.
 *
 * @package	diy-blog.model
 * @author	Martynas Jusevicius <hide@address.com>
 * @link	http://www.xml.lt
 */

class AdminFilesResource extends BackEndResource
{

	/**
	 * Constructs a new AdminFilesResource class, setting the Type column to BackEndResourcePeer::CLASSKEY_ADMINFILESRESOURCE.
	 */
	public function __construct()
	{

		$this->setType(BackEndResourcePeer::CLASSKEY_ADMINFILESRESOURCE);
	}

	public function doGet(Request $request, Response $response)
	{
		$view = null;
		$parent = parent::doGet($request, $response);

		if ($parent != null) $view = $parent;
		else $view = new FilesView($this);

		return $view;
	}

	public function doPost(Request $request, Response $response)
	{
		$view = null;
		$parent = parent::doPost($request, $response);

		if ($parent != null) $view = $parent;
		else
		{
			if ($request->getParameter("action") == "upload")
			{
				$errors = array();
				$form = new FileForm($request);
				$errors = $form->validate();

				try
				{
					if (count($errors) != 0) throw new InvalidFormException();

					//$rootDir = $request->getHeader("DOCUMENT_ROOT");
					//$fileDir = $rootDir."/static/files/";
					$fileDir = "static/files/";

					$result = move_uploaded_file($form->getFilesystemName(), $fileDir.$form->getOriginalName());
					$request->setAttribute("file-result", "success");
				}
				catch (InvalidFormException $e)
				{
					$request->setAttribute("file-result", "failure");
				}

				$request->setAttribute("file-form", $form);
				$request->setAttribute("file-errors", $errors);
			}

			$view = new FilesView($this);
		}

		return $view;
	}

} // AdminFilesResource
Return current item: DIY Blog