Ejemplo n.º 1
0
 function doUpload($file)
 {
     if (!preg_match('/(\\.map\\.gbx)$/ixu', $file)) {
         throw new \ManiaLib\Application\UserException('Please upload only maps');
     }
     try {
         $path = '$uploaded/' . $this->session->login . '/';
         $connection = $this->getServerConnection();
         $mapsPath = $connection->getMapsDirectory();
         $mapService = new \ManiaHost\Services\MapService($mapsPath);
         $maxSize = 20 * pow(2, 20) - $mapService->getSize($path, array(), null, null, null, null, true);
         $maxSize = $maxSize > pow(2, 20) ? pow(2, 20) : $maxSize;
         $data = file_get_contents('php://input', null, null, null, $maxSize);
         $connection->writeFileFromString($path . $file, $data);
         $datas = $mapService->getData($mapsPath . $path . $file);
         $map = new \ManiaHost\Services\Map();
         $map->filename = $file;
         $map->path = $path;
         foreach ($datas as $key => $value) {
             $map->{$key} = $value;
         }
         $mapService->register($map);
     } catch (\Exception $e) {
         \ManiaLib\Application\ErrorHandling::logException($e);
         $this->request->set('message', 'An error append during upload');
         $this->request->redirectArgList('../upload/', 'message');
     }
     $this->request->set('message', 'file successfully uploaded');
     $this->request->redirectArgList('../upload/', 'message');
 }