|
|
@@ -5,24 +5,41 @@ class file
|
|
|
public static function record(array $_temp, string $_folderFiles = DIR_DATAS_FILES)
|
|
|
{
|
|
|
$md5 = md5_file($_temp["tmp_name"]);
|
|
|
- if (copy($_temp["tmp_name"], $_folderFiles . $md5)) {
|
|
|
- db::query("INSERT INTO " . DB_T_FILES . " (id, name, size, id_user) VALUES (:id, :name, :size, :id_user)");
|
|
|
- db::bind(':id', $md5);
|
|
|
- db::bind(':name', $_temp['name']);
|
|
|
- db::bind(':size', $_temp['size']);
|
|
|
- db::bind(':id_user', session::getId());
|
|
|
|
|
|
- try {
|
|
|
- db::execute();
|
|
|
- return $md5;
|
|
|
- } catch (Exception $ex) {
|
|
|
- unlink($_folderFiles . $md5);
|
|
|
- alert::recError("Erreur #record sur l'import du fichier " . $_temp['name']);
|
|
|
- return FALSE;
|
|
|
+ if(self::findM5($md5) == FALSE){
|
|
|
+ if (copy($_temp["tmp_name"], $_folderFiles . $md5)) {
|
|
|
+ db::query("INSERT INTO " . DB_T_FILES . " (id, name, size, id_user) VALUES (:id, :name, :size, :id_user)");
|
|
|
+ db::bind(':id', $md5);
|
|
|
+ db::bind(':name', $_temp['name']);
|
|
|
+ db::bind(':size', $_temp['size']);
|
|
|
+ db::bind(':id_user', session::getId());
|
|
|
+
|
|
|
+ try {
|
|
|
+ db::execute();
|
|
|
+ return $md5;
|
|
|
+ } catch (Exception $ex) {
|
|
|
+ unlink($_folderFiles . $md5);
|
|
|
+ alert::recError("Erreur #record sur l'import du fichier " . $_temp['name']);
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
}
|
|
|
+ } else {
|
|
|
+ alert::recError("Erreur #record ce fichier a déjà été importé : " . $_temp['name']);
|
|
|
+ return FALSE;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static function findM5(string $_md5)
|
|
|
+ {
|
|
|
+ db::query("SELECT "
|
|
|
+ . "IF(" . DB_T_FILES . ".name IS NOT NULL, TRUE, FALSE) AS exist "
|
|
|
+ . "FROM " . DB_T_FILES . " "
|
|
|
+ . "WHERE " . DB_T_FILES . ".id = :md5");
|
|
|
+ db::bind(':md5', $_md5);
|
|
|
+ $return = db::single();
|
|
|
+ return ($return == TRUE) ? TRUE : FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
public static function delete(string $_id = NULL, string $_folderFiles = DIR_DATAS_FILES)
|
|
|
{
|
|
|
if (isset($_id) and $_id != NULL and file_exists($_folderFiles . $_id)) {
|