ADD возможность загружать файлы треков
This commit is contained in:
parent
28591415fa
commit
2663d00739
|
|
@ -23,5 +23,9 @@ public/photos/big/*.jpeg
|
|||
public/photos/big/*.png
|
||||
public/photos/big/*.gif
|
||||
|
||||
tracks/*.gpx
|
||||
tracks/*.kml
|
||||
tracks/*.kmz
|
||||
|
||||
logs/*
|
||||
.idea
|
||||
|
|
|
|||
|
|
@ -204,30 +204,9 @@ abstract class Model
|
|||
* @param array $values - ассоциативный массив соо значениями.
|
||||
* @return object - id добавленной записи или false.
|
||||
*/
|
||||
function add2($values)
|
||||
{
|
||||
$values = $this->_vals_;
|
||||
unset($values[$this->_primaryKey_]);
|
||||
|
||||
$q = array();
|
||||
foreach ($values as $val) {
|
||||
$q[] = '?';
|
||||
}
|
||||
|
||||
var_dump('INSERT INTO `' . $this->_tableName_ . '` (`' . implode('`, `', array_keys($values)) . '`) VALUES (' . implode(', ', array_values($q)) . ') ');
|
||||
die;
|
||||
$res = App::DB()->prepare_query('INSERT INTO `' . $this->_tableName_ . '` (`' . implode('`, `', array_keys($values)) . '`) VALUES (' . implode(', ', array_values($q)) . ') ', self::arrayWithTypes($values));
|
||||
|
||||
if ($res) {
|
||||
throw new Exception('MySQL error #' . $res->errno . ' - ' . $res->error);
|
||||
}
|
||||
|
||||
return $this->getByPK(App::DB()->insert_id);
|
||||
}
|
||||
|
||||
function add($values)
|
||||
{
|
||||
$request = App::DB()->prepare('INSERT INTO ' . $this->_tableName_ . ' (' . implode(',', array_keys($values)) . ') values (:' . implode(', :', array_keys($values)) . ')');
|
||||
$request = App::DB()->prepare('INSERT INTO `' . $this->_tableName_ . '` (`' . implode('`, `', array_keys($values)) . '`) values (:' . implode(', :', array_keys($values)) . ')');
|
||||
if ($request->execute((array) $values)) {
|
||||
return $this->getByPK(App::DB()->lastInsertId());
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ class IndexController extends Controller
|
|||
|
||||
static function actionTest()
|
||||
{
|
||||
// $gpxObject = simplexml_load_file('/tmp/doc2.gpx');
|
||||
$gpxObject = simplexml_load_file('/tmp/doc(gpsvisualizer.com).gpx');
|
||||
$gpxObject = simplexml_load_file('/tmp/2.gpx');
|
||||
// $gpxObject = simplexml_load_file('/tmp/doc(gpsvisualizer.com).gpx');
|
||||
// $gpxObject = simplexml_load_file('/tmp/1100.gpx');
|
||||
|
||||
$trip = array(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
class TracksController extends Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
self::$layout = 'layouts/page.php';
|
||||
self::addStyle('/css/style.css?ver=' . App::getConfig('version'));
|
||||
self::addStyle('/css/pageStyle.css?ver=' . App::getConfig('version'));
|
||||
self::addScript('/js/jquery-2.1.0.min.js');
|
||||
self::addScript('/js/jquery-ui-1.10.4.custom.min.js');
|
||||
self::addScript('/js/bootstrap.min.js');
|
||||
self::addStyle('/css/bootstrap.min.css');
|
||||
self::addStyle('/css/bootstrap-theme.min.css');
|
||||
|
||||
}
|
||||
|
||||
function actionMy()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function actionFiles()
|
||||
{
|
||||
$files = TrackFiles::model()->getAll(array('where' => '`owner` = :owner'), array('owner' => App::$user->id));
|
||||
|
||||
self::render('/tracks/files.php', array(
|
||||
'files' => $files,
|
||||
));
|
||||
}
|
||||
|
||||
function actionUploadfile()
|
||||
{
|
||||
//var_dump($_POST, $_FILES);
|
||||
$temp = pathinfo($_FILES['file']['name']);
|
||||
$filename = $_FILES['file']['name'];
|
||||
$extension = strtolower($temp['extension']);
|
||||
$uploaddir = App::getBasedir().'tracks/';
|
||||
// var_dump($extension);die;
|
||||
if ($extension !== 'gpx') {
|
||||
App::error404('Неизвестный тип');
|
||||
}
|
||||
|
||||
$tmp = TrackFiles::model()->add(array(
|
||||
'owner' => App::$user->id,
|
||||
'name' => 'Трек '.date('d-m-Y H:i:s'),
|
||||
'filename' => $filename,
|
||||
'createdAt' => date('c'),
|
||||
));
|
||||
|
||||
$newName = 'track'.$tmp->id . '.' . $extension;
|
||||
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploaddir . $newName)) {
|
||||
var_dump($tmp);
|
||||
} else {
|
||||
App::error404();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
class TrackFiles extends Model
|
||||
{
|
||||
|
||||
function __construct($fromArray = array())
|
||||
{
|
||||
$this->_tableName_ = 'trackFiles';
|
||||
parent::__construct($fromArray);
|
||||
}
|
||||
|
||||
static function model()
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<form method="POST" action="/tracks/uploadfile/" enctype="multipart/form-data" class="form-inline">
|
||||
<div class="form-group">
|
||||
<label for="uploadfile">Загрузить новый файл</label>
|
||||
<input type="file" name="file" id="uploadfile" class="form-control" accept=".gpx"/>
|
||||
<button type="submit" class="btn btn-success" title="Загрузить выбранный файл"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span></button>
|
||||
</div>
|
||||
</form>
|
||||
<hr/>
|
||||
<h3>Ваши файлы с треками</h3>
|
||||
<?php
|
||||
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
print $file->id . ' — ' . $file->name . ' ('. $file->filename.')<br/>';
|
||||
}
|
||||
} else {
|
||||
print 'Пока ничего не загружено';
|
||||
}
|
||||
Loading…
Reference in New Issue