Beispiel #1
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'));
 }
Beispiel #2
0
 public function upload($options = [])
 {
     $this->_enforceExists();
     if ($this->method == 'POST' && Input::hasFile('file')) {
         $file = Input::file('file');
         if ($file['error']) {
             throw new InternalErrorException();
         }
         if (!in_array($file['type'], Config::get('filetype'))) {
             throw new ForbiddenException('Invalid file type');
         }
         if ($file['size'] > Config::get('maxsize')) {
             throw new ForbiddenException('Too large file');
         }
         if (!is_uploaded_file($file['tmp_name'])) {
             throw new ForbiddenException('Invalid file');
         }
         $id = $this->page->getId() . '_' . sha1($file['name']);
         $dst = dirname(dirname(dirname(__FILE__))) . '/file/' . $id;
         if (!move_uploaded_file($file['tmp_name'], $dst)) {
             throw new InternalErrorException();
         }
         file_put_contents($dst . '.json', json_encode($file));
         return $this->redirect('?a=edit&p=' . urlencode($this->page->name));
     }
 }
Beispiel #3
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]);
         }
     }
 }