-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave.php
More file actions
40 lines (32 loc) · 1.02 KB
/
save.php
File metadata and controls
40 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
$params = require 'config.php';
try {
$dsn = sprintf("mysql:host=%s;dbname=%s", $params['host'], $params['db']);
$pdo = new PDO($dsn, $params['user'], $params['pwd']);
} catch (PDOException $e) {
echo $e->getMessage();
} catch (Throwable $e) {
echo $e->getMessage();
}
$nombre = filter_var($_POST['nombre'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$archivo = file_get_contents($_FILES["archivo"]["tmp_name"]);
$extension = pathinfo($_FILES["archivo"]["name"], PATHINFO_EXTENSION);
$sql = "INSERT INTO archivos (nombre, extension, archivo) VALUES (:nombre, :extension, :archivo)";
$sentencia = $pdo->prepare($sql);
$sentencia->execute([
':nombre' => $nombre,
':extension' => $extension,
':archivo' => $archivo,
]);
/**
* para probar si hay errores
*/
$arr = $sentencia->errorInfo();
print_r($arr);
$query = $pdo->prepare("SELECT * FROM archivos");
$query->execute();
$registros = $query->fetchAll();
require 'save_success.php';
/*while ($row = $sentencia->fetch(PDO::FETCH_ASSOC)) {
print_r($row);
}*/