Example #1
0
 public function upload()
 {
     if (Input::hasFile('files') && $this->method === 'POST') {
         $files = Input::file('files');
         $num = count($files['name']);
         $saved = 0;
         for ($i = 0; $i < $num; ++$i) {
             $file = array_combine(array_keys($files), array_map(function ($value) use($i) {
                 return $value[$i];
             }, array_values($files)));
             if (!is_uploaded_file($file['tmp_name'])) {
                 throw new InternalErrorException();
             }
             $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
             if ($ext == 'md') {
                 $markdown = file_get_contents($file['tmp_name']);
                 $page_name = basename($file['name'], '.md');
                 $markdown = preg_replace_callback('/Title: (.*?)(\\r\\n|\\r|\\n)/', function ($matches) use(&$page_name) {
                     $page_name = $matches[1];
                     return '';
                 }, $markdown);
                 $page = new Page($page_name, 'name');
                 $page->update($markdown);
                 ++$saved;
             }
         }
         if ($saved == 1) {
             return $this->redirect(['p' => $page_name]);
         }
     }
 }
Example #2
0
 public function testFile()
 {
     $file = Input::file('file1');
     $this->assertEquals('file1.txt', $file['name']);
     $this->assertEquals('text/plain', $file['type']);
     $this->assertNull(Input::file('file0'));
 }
Example #3
0
 public function file()
 {
     $this->_enforceExists();
     if (!Input::has('f')) {
         throw new ForbiddenException();
     }
     $name = Input::get('f');
     $id = $this->page->getId() . '_' . sha1($name);
     $path = dirname(dirname(dirname(__FILE__))) . '/file/' . $id;
     if (!file_exists($path)) {
         throw new NotFoundException("A file \"{$name}\" is not found");
     }
     $json = $path . '.json';
     if (!file_exists($json)) {
         throw new NotFoundException("Informations of the file \"{$name}\" are not found");
     }
     $file = json_decode(file_get_contents($json), true);
     header('Content-Type: ' . $file['type']);
     header('Content-Length: ' . $file['size']);
     header('Content-Disposition: inline; filename="' . str_replace('"', '?', $file['name']) . '"');
     echo file_get_contents($path);
     return false;
 }
Example #4
0
File: index.php Project: hawkao/mew
<?php

require_once __DIR__ . '/vendor/autoload.php';
use ukatama\Mew\Config;
use ukatama\Mew\Input;
use ukatama\Mew\PageController;
use ukatama\Mew\Registry;
ini_set('display_errors', Config::get('debug'));
try {
    Registry::controller(Input::get('c', 'page'))->dispatch(Input::get('a', 'view'));
} catch (Exception $e) {
    $ctr = Registry::controller('error');
    $ctr->error = $e;
    $ctr->dispatch('error');
}