Created
October 28, 2018 14:30
-
-
Save web-crab/d78de552a41d22cf697b222d1fa3ed8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$domain = "example.com"; | |
// Подключение к БД | |
$host = ""; | |
$user = ""; | |
$pass = ""; | |
$db = ""; | |
// Данные Email | |
$from = ""; | |
$to = ""; | |
/** | |
* Функция записи данных в таблицу БД | |
* $table - имя таблицы. Имена столбцов должны совпадать с атрибутами name у передаваемых полей | |
* $fields - $_POST-массив полей | |
*/ | |
function addToDB($table, $fields) { | |
$sql = "INSERT INTO $table SET"; | |
$i = 0; | |
foreach($fields as $k => $v) { | |
$i++; | |
$sql .= " $k='$v'"; | |
if ($i != count($fields)) $sql .= ','; | |
} | |
$mysqli = new mysqli($host, $user, $pass, $db); | |
$mysqli->set_charset('utf8'); | |
$mysqli->query($sql); | |
$mysqli->close(); | |
} | |
/** | |
* Функция отправки HTML-письма на почту | |
* $sbj - тема письма | |
* $msg - содержимое | |
*/ | |
function sendMail($sbj, $msg) { | |
$headers = "Content-type: text/html; charset=utf-8\r\n"; | |
$headers .= "From: <$from>\r\n"; | |
mail($to, $sbj, $msg, $headers); | |
} | |
/** | |
* Функция загрузки файлов на сервер, в папку php/files/. Возвращает список ссылок на загруженные файлы | |
* $filesList - $_FILES-массив файлов | |
*/ | |
function uploadFiles($filesList) { | |
$pathForLinks = "http://www.$domain/php/files"; | |
$linksList = []; | |
foreach ($filesList["error"] as $key => $error) { | |
if ($error == "0") { | |
$tmp_name = $filesList["tmp_name"][$key]; | |
$name = str_replace(" ", "_", $filesList["name"][$key]); | |
$name = basename($name); | |
$linksList[$key] = "$pathForLinks/$name"; | |
move_uploaded_file($tmp_name, "./files/$name"); | |
} | |
} | |
return $linksList; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment