Example #1
0
 public static function run($request)
 {
     if (!$request instanceof Request) {
         $request = new Request($request);
     }
     $file = $request->getFile();
     $class = $request->getClass();
     $method = $request->getMethod();
     $args = $request->getArgs();
     $front = FrontController::getInstance();
     $registry = $front->getRegistry();
     $registry->oRequest = $request;
     $front->setRegistry($registry);
     if (file_exists($file)) {
         require_once $file;
         $rc = new ReflectionClass($class);
         // if the controller exists and implements IController
         //			if($rc->implementsInterface('IController'))
         if ($rc->isSubclassOf('BaseController')) {
             try {
                 $controller = $rc->newInstance();
                 $classMethod = $rc->getMethod($method);
                 return $classMethod->invokeArgs($controller, $args);
             } catch (ReflectionException $e) {
                 throw new MvcException($e->getMessage());
             }
         } else {
             //				throw new MvcException("Interface iController must be implemented");
             throw new MvcException("abstract class BaseController must be extended");
         }
     } else {
         throw new MvcException("Controller file not found");
     }
 }
    {
        $localPath = $this->downloadTemp($path);
        if ($localPath) {
            return @file_get_contents($localPath);
        }
    }
}
ExceptionCatcherJSON::register();
$oResponse = new Response();
$oFtp = new FileManager(array('hostname' => '', 'username' => '', 'password' => ''));
if (!$oFtp->connect()) {
    throw new Exception("Cannot connect to the FTP server");
}
if (Request::getFile() && ($dest = Request::getPost('destination'))) {
    $errors = array();
    foreach (Request::getFile() as $file) {
        $filePath = $file['tmp_name'];
        $destPath = $dest . '/' . $file['name'];
        $result = $oFtp->upload($filePath, $destPath);
        if (!$result) {
            $errors[] = $file['name'];
        }
    }
    if ($errors) {
        throw new Exception("Unknown error uploading: \n\n" . implode(", \n", $errors));
    }
    $oResponse->setData($result);
    $oResponse->flushJson();
}
if (Request::getApiParam('mode') === 'list') {
    $list = $oFtp->listFilesRaw(Request::getApiParam('path'));
Example #3
0
 public static function getImageFile($key, $allowedMimeTypes = array())
 {
     if (!($file = Request::getFile($key))) {
         return false;
     }
     if (empty($allowedMimeTypes)) {
         $allowedMimeTypes = MimeType::getDefaultInternetImageTypeList();
     }
     if (!in_array($file['type'], $allowedMimeTypes)) {
         throw new Exception\NotAllowedFileType();
     }
     // IMPLEMENTAR VERIFICAÇÃO DA EXTENSÃO DA IMAGEM
     // $extList = array_keys ( $allowedMimeTypes );
     // $fileExt = EXTENSAO EXTRAIDA DE => $file['name'] ;
     // if ( !in_array ( $fileExt , $extList ) ) throw new Exception\NotAllowedFileType();
     return new Upload($file);
     // return $file ;
 }