Commit 9ed64945 authored by Gabriel Moreau's avatar Gabriel Moreau
Browse files

Bug when summit datasheet

parent 9b96ebd3
......@@ -84,6 +84,8 @@ if ($pdo = connect_db()) {
echo 'Erreur : '. $err_msg.'<br>';
if ($notice != '')
$id_datasheet = set_datasheet_new($pdo, $id_equipment, $_FILES["notice"]["name"], $_FILES["notice"]["tmp_name"]);
if (!$id_datasheet)
echo 'Erreur : la notice n\'est pas prise en compte car elle n\'est pas un fichier au format PDF !<br>';
} //end if connect
echo '<br>Ajout de '.$nom.' valid&eacute;e';
......
......@@ -99,7 +99,8 @@ if ($pdo = connect_db()) {
echo 'Erreur : '. $err_msg.'<br>';
if ($notice != '') {
$id_datasheet = set_datasheet_new($pdo, $id_equipment, $_FILES["notice"]["name"], $_FILES["notice"]["tmp_name"]);
echo "New datasheet ".$id_equipment." number # ".$id_datasheet;
if (!$id_datasheet)
echo 'Erreur : la notice n\'est pas prise en compte car elle n\'est pas un fichier au format PDF !<br>';
}
} // end if modif
else {
......
......@@ -95,19 +95,20 @@ function get_datasheet_count_by_equipment($pdo, $id_equipment) {
// ---------------------------------------------------------------------
function set_datasheet_new($pdo, $equipment_id, $equipment_name, $tmp_file) {
if (!preg_match('/\.pdf$/i', $tmp_file))
function set_datasheet_new($pdo, $equipment_id, $datasheet_filename_upload, $tmp_file) {
if (!preg_match('/\.pdf$/i', $datasheet_filename_upload))
return false;
$new_datasheet_path = './data/datasheet';
if (!is_dir($new_datasheet_path))
mkdir($new_datasheet_path, 0755);
$datasheet_filename_kebab = string_to_filename_kebab($equipment_name);
$datasheet_filename_kebab = string_to_filename_kebab($datasheet_filename_upload);
$datasheet_filename_no_ext = pathinfo($datasheet_filename_upload, PATHINFO_FILENAME);
$sql1 = 'INSERT INTO datasheet (description, id_equipment) VALUES (?, ?);';
$stmt1 = $pdo->prepare($sql1);
$stmt1->execute(array($equipment_name, $equipment_id));
$stmt1->execute(array($datasheet_filename_no_ext, $equipment_id));
$id_datasheet = $pdo->lastInsertId();
$sub_path = $id_datasheet.'-'.random_string(8);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment