You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.2 KiB
PHTML
76 lines
2.2 KiB
PHTML
2 years ago
|
<?php
|
||
|
|
||
|
include('config.inc.php');
|
||
|
|
||
|
$db = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['database'], $config['dbuser'], $config['password'], [
|
||
|
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
|
||
|
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'"
|
||
|
]);
|
||
|
|
||
|
if (isset($_FILES))
|
||
|
{
|
||
|
$termIds = array(); // cmdid => id
|
||
|
$paramTermId = isset($_GET['termId']) ? intval($_GET['termId']) : 0;
|
||
|
|
||
|
$sql = "INSERT INTO mntn_uploads(term_id,`file_name`,`path`,`file_size`) VALUES(:termId,:fileName,:path,:fileSize)";
|
||
|
$stmt = $db->prepare($sql);
|
||
|
$stmt2 = null;
|
||
|
|
||
|
foreach ($_FILES as $file)
|
||
|
{
|
||
|
$cmdid = '';
|
||
|
$pos = strpos($file['name'], '_');
|
||
|
if ($pos !== false)
|
||
|
{
|
||
|
$cmdid = substr($file['name'], 0, $pos);
|
||
|
}
|
||
|
|
||
|
$termId = $paramTermId;
|
||
|
if ($termId === 0)
|
||
|
{
|
||
|
if (isset($termIds[$cmdid]))
|
||
|
{
|
||
|
$termId = $termIds[$cmdid];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if ($stmt2 == null)
|
||
|
{
|
||
|
$sql = "SELECT `id` FROM terminals WHERE cmdid=:cmdid";
|
||
|
$stmt2 = $db->prepare($sql);
|
||
|
}
|
||
|
|
||
|
if ($stmt2->execute(array('cmdid' => $cmdid)))
|
||
|
{
|
||
|
$row = $stmt2->fetch();
|
||
|
if ($row)
|
||
|
{
|
||
|
$termIds[$cmdid] = $row['id'];
|
||
|
$termId = $row['id'];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$fileName = date('Ymd') . '_' . uniqid('log_');
|
||
|
$dest = $config['term_logs_root'] . $fileName;
|
||
|
|
||
|
if (!move_uploaded_file($file['tmp_name'], $dest))
|
||
|
{
|
||
|
// error_log("move_uploaded_file failed: " . $dest);
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
$res = $stmt->execute(array('termId' => $termId, 'fileName' => $file['name'], 'path' => $fileName, 'fileSize' => $file['size']));
|
||
|
if (!$res)
|
||
|
{
|
||
|
// error_log(print_r($stmt->errorInfo(), true));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$result['code'] = 0;
|
||
|
|
||
|
header ('Content-type: application/json; charset=utf-8');
|
||
|
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|