/** * Move uploaded files from temp to upload directory with new name. * * @return void. */ public function move() { $names = array(); try { if (!empty($_FILES)) { $num = 0; foreach ($_FILES["files"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $check = new \check_file($key, array("tcx", "gpx")); $num++; $file_type = end(explode(".", $_FILES["files"]["name"][$key])); $file_name = "gpsdata" . $num . "." . $file_type; $this->uploadfile[] = $this->uploaddir . $file_name; $names[$num] = $file_name; if (!move_uploaded_file($_FILES["files"]["tmp_name"][$key], $this->uploadfile[$num - 1])) { throw new \Exception("Cannot save file " . $_FILES["files"]["tmp_name"][$key] . " as " . $this->uploadfile[$num - 1]); } } else { echo $error; } } $_SESSION['names'] = $names; $this->redirect($this->generateUrl('homepage')); } else { throw new \Exception("There is no uploaded files"); } } catch (\Exception $e) { $catcher = new \catcher($e); $catcher->show(); } }
/** * Wyœwietla kod HTML szablonu * * @param string $name Nazwa pliku * @param string $path Œcie¿ka do szablonu * * @return void */ public function renderHTML($name, $path = '') { $path = DIR_TEMPLATE . $path . $name . '.html'; try { if (is_file($path)) { require $path; } else { throw new \Exception('Can not open template ' . $name . ' in: ' . $path); } } catch (\Exception $e) { $catcher = new \catcher($e); $catcher->show(); } }
/** * Load given file into object and return him. * * @param Integer $id Id of file to load * * @return IActive */ public function loadFile($id) { $name = $_SESSION["names"][$id]; try { if (file_exists(DIR_UPLOAD . $name)) { $parse = new \parseFile(); $this->activity = $parse->parse($name); return $this->activity; } else { throw new \Exception("There is no files with that name"); } } catch (\Exception $e) { $catcher = new \catcher($e); $catcher->show(); } }
/** * Compare filename extensions of uploaded file with allowed extensions. * * @return void */ private function checktype() { $file_type = end(explode(".", $_FILES["files"]["name"][$this->File])); $match = false; foreach ($this->type as $type) { if ($type == $file_type) { $match = true; } } try { if (!$match) { throw new \Exception("Wrong filename extension. Allowed extension are " . join($this->type, ", ") . "."); } } catch (\Exception $e) { $catcher = new \catcher($e); $catcher->show(); } }
/** * Creates path for file based on id. * * @param integer $id Id of file. * * @return string Path to the file. */ public function getFileName($id) { try { $name = DIR_UPLOAD . $_SESSION["names"][$id]; if (file_exists($name)) { return $name; } else { throw new \Exception("There is no files with that name"); } } catch (\Exception $e) { $catcher = new \catcher($e); $catcher->show(); } }