function explnum_add_from_url($f_notice_id, $f_bulletin_id, $f_nom, $f_url, $overwrite = true, $source_id = 0, $filename = '', $f_path = '', $f_statut) { global $dbh, $base_path; if ($f_bulletin_id) { $f_notice_id = 0; } else { if (!$f_bulletin_id && $f_notice_id) { $f_bulletin_id = 0; } } if (!$overwrite) { $sql_find = "SELECT count(*) FROM explnum WHERE explnum_notice = " . $f_notice_id . " AND explnum_nom = '" . addslashes($f_nom) . "'"; $res = pmb_mysql_query($sql_find, $dbh); $count = pmb_mysql_result($res, 0, 0); if ($count) { return; } } $sql_delete = "DELETE FROM explnum WHERE explnum_notice = " . $f_notice_id . " AND explnum_nom = '" . addslashes($f_nom) . "' "; pmb_mysql_query($sql_delete, $dbh); $original_filename = basename($f_url); $extension = substr($original_filename, strripos($original_filename, '.') * 1 + 1); $tmp_filename = explnum::static_rename($extension); if ($filename) { $new_filename = $filename; } else { $new_filename = $tmp_filename; } //copie en répertoire temporaire $r = false; if (file_exists($f_url) && filesize($f_url)) { //document en repertoire $r = copy($f_url, $base_path . '/temp/' . $tmp_filename); } else { //url $aCurl = new Curl(); $content = $aCurl->get($f_url); $content = $content->body; $r = file_put_contents("{$base_path}/temp/" . $tmp_filename, $content); } if ($r) { //construction vignette $vignette = construire_vignette('', $tmp_filename); create_tableau_mimetype(); $mimetype = trouve_mimetype("{$base_path}/temp/" . $tmp_filename, $extension); //si la source du connecteur est précisée, on regarde si on a pas un répertoire associé $rep_upload = 0; if ($source_id) { $check_rep = "select rep_upload from connectors_sources where source_id = " . $source_id; $res = pmb_mysql_query($check_rep); if (pmb_mysql_num_rows($res)) { $rep_upload = pmb_mysql_result($res, 0, 0); } } if ($rep_upload != 0) { $upload_folder = new upload_folder($rep_upload); $rep_path = $upload_folder->get_path($new_filename); if ($f_path && file_exists($rep_path . $f_path)) { $rep_path = $rep_path . $f_path . '/'; } if (file_exists($upload_folder->encoder_chaine($rep_path . $new_filename))) { $suffix = 1; $ext = extension_fichier($new_filename); $file = str_replace("." . $ext, "", basename($new_filename)); while (file_exists($upload_folder->encoder_chaine($rep_path . $file . "_" . $suffix . "." . $ext))) { $suffix++; } $new_filename = $file . "_" . $suffix . "." . $ext; } rename("{$base_path}/temp/" . $tmp_filename, $upload_folder->encoder_chaine($rep_path . $new_filename)); $path = $upload_folder->formate_path_to_save($upload_folder->formate_path_to_nom($rep_path)); $insert_sql = "INSERT INTO explnum (explnum_notice, explnum_bulletin, explnum_nom, explnum_nomfichier, explnum_mimetype, explnum_extfichier, explnum_vignette, explnum_repertoire, explnum_path, explnum_docnum_statut) VALUES ("; $insert_sql .= $f_notice_id . ","; $insert_sql .= $f_bulletin_id . ","; $insert_sql .= "'" . addslashes($f_nom) . "',"; $insert_sql .= "'" . addslashes($new_filename) . "',"; $insert_sql .= "'" . addslashes($mimetype) . "',"; $insert_sql .= "'" . addslashes($extension) . "',"; $insert_sql .= "'" . addslashes($vignette) . "',"; $insert_sql .= "'" . addslashes($rep_upload) . "',"; $insert_sql .= "'" . addslashes($path) . "',"; $insert_sql .= $f_statut; $insert_sql .= ")"; } else { $insert_sql = "INSERT INTO explnum (explnum_notice, explnum_bulletin, explnum_nom, explnum_nomfichier, explnum_mimetype, explnum_extfichier, explnum_data, explnum_vignette, explnum_docnum_statut) VALUES ("; $insert_sql .= $f_notice_id . ","; $insert_sql .= $f_bulletin_id . ","; $insert_sql .= "'" . addslashes($f_nom) . "',"; $insert_sql .= "'" . addslashes($new_filename) . "',"; $insert_sql .= "'" . addslashes($mimetype) . "',"; $insert_sql .= "'" . addslashes($extension) . "',"; $insert_sql .= "'" . addslashes($content) . "',"; $insert_sql .= "'" . addslashes($vignette) . "',"; $insert_sql .= $f_statut; $insert_sql .= ")"; } if (pmb_mysql_query($insert_sql, $dbh)) { $docnum_id = pmb_mysql_insert_id($dbh); if ($docnum_id) { $index = new indexation_docnum($docnum_id); $index->indexer(); } } /* $aCurl = new Curl(); $content = $aCurl->get($f_url); $content = $content->body; $origine=str_replace(" ","",microtime()); $origine=str_replace("0.","",$origine); $original_filename = basename($f_url); if( $filename != "") $afilename = $filename; else $afilename = $origine.$original_filename; if (!$original_filename) $original_filename = $afilename; file_put_contents("$base_path/temp/".$afilename, $content); */ /* $vignette = construire_vignette('', $afilename); create_tableau_mimetype(); $afilename_ext=extension_fichier($afilename); $mimetype = trouve_mimetype("$base_path/temp/".$afilename, $afilename_ext); $extension = strrchr($afilename, '.'); //si la source du connecteur est précisée, on regarde si on a pas un répertoire associé if ($source_id){ $check_rep = "select rep_upload from connectors_sources where source_id = ".$source_id; $res = pmb_mysql_query($check_rep); if(pmb_mysql_num_rows($res)){ $rep_upload = pmb_mysql_result($res,0,0); } } */ /* if($rep_upload != 0){ $upload_folder = new upload_folder($rep_upload); $rep_path = $upload_folder->get_path($afilename); if ($f_path && file_exists($rep_path.$f_path)) { $rep_path=$rep_path.$f_path.'/'; } copy("$base_path/temp/".$afilename,$rep_path.$afilename); $path =$upload_folder->formate_path_to_save($upload_folder->formate_path_to_nom($rep_path)); $insert_sql = "INSERT INTO explnum (explnum_notice, explnum_nom, explnum_nomfichier, explnum_mimetype, explnum_extfichier, explnum_vignette, explnum_repertoire, explnum_path) VALUES ("; $insert_sql .= $f_notice_id.","; $insert_sql .= "'".addslashes($f_nom)."',"; $insert_sql .= "'".addslashes($afilename)."',"; $insert_sql .= "'".addslashes($mimetype)."',"; $insert_sql .= "'".addslashes($extension)."',"; $insert_sql .= "'".addslashes($vignette)."',"; $insert_sql .= "'".addslashes($rep_upload)."',"; $insert_sql .= "'".addslashes($path)."'"; $insert_sql .= ")"; }else{ $insert_sql = "INSERT INTO explnum (explnum_notice, explnum_nom, explnum_nomfichier, explnum_mimetype, explnum_extfichier, explnum_data, explnum_vignette) VALUES ("; $insert_sql .= $f_notice_id.","; $insert_sql .= "'".addslashes($f_nom)."',"; $insert_sql .= "'".addslashes($afilename)."',"; $insert_sql .= "'".addslashes($mimetype)."',"; $insert_sql .= "'".addslashes($extension)."',"; $insert_sql .= "'".addslashes($content)."',"; $insert_sql .= "'".addslashes($vignette)."'"; $insert_sql .= ")"; } pmb_mysql_query($insert_sql, $dbh); unlink("$base_path/temp/".$afilename); */ } }
function get_file_from_temp($filename, $name, $upload_place) { global $base_path; global $ck_index; global $id_rep, $up_place; $up_place = $upload_place; create_tableau_mimetype(); $ck_index = true; //Initialisation des tableaux d'infos $this->infos_docnum = $this->params = array(); $this->infos_docnum["mime"] = trouve_mimetype($filename, extension_fichier($name)); $this->infos_docnum["nom"] = substr($name, 0, strrpos($name, ".")); if (!$this->infos_docnum["nom"]) { $this->infos_docnum["nom"] = $name; } $this->infos_docnum["notice"] = $this->explnum_notice; $this->infos_docnum["bull"] = $this->explnum_bulletin; $this->infos_docnum["url"] = ""; $this->infos_docnum["fic"] = false; $this->infos_docnum["contenu_vignette"] = construire_vignette('', substr($filename, strrpos($filename, "/"))); $this->infos_docnum["userfile_name"] = $name; $this->infos_docnum["userfile_ext"] = extension_fichier($name); if ($up_place && $id_rep != 0) { $upfolder = new upload_folder($id_rep); $chemin_hasher = "/"; if ($upfolder->isHashing()) { $rep = $upfolder->hachage($this->infos_docnum["userfile_name"]); @mkdir($rep); $chemin_hasher = $upfolder->formate_path_to_nom($rep); $file_name = $rep . $this->infos_docnum["userfile_name"]; $chemin = $upfolder->formate_path_to_save($chemin_hasher); } else { $file_name = $upfolder->get_path($this->infos_docnum["userfile_name"]) . $this->infos_docnum["userfile_name"]; $chemin = $upfolder->formate_path_to_save("/"); } $this->infos_docnum["path"] = $chemin; $file_name = $upfolder->encoder_chaine($file_name); if (!$this->explnum_nomfichier) { //Si je suis en création de fichier numérique $nom_tmp = $this->infos_docnum["userfile_name"]; $continue = true; $compte = 1; do { $query = "select explnum_notice,explnum_id from explnum where explnum_nomfichier = '" . addslashes($nom_tmp) . "' AND explnum_repertoire='" . $id_rep . "' AND explnum_path='" . addslashes($this->infos_docnum["path"]) . "'"; $result = mysql_query($query); if (mysql_num_rows($result) && mysql_result($result, 0, 0) != $this->infos_docnum["notice"]) { //Si j'ai déjà un document numérique avec ce fichier pour une autre notice je dois le renommer pour ne pas perdre l'ancien if (preg_match("/^(.+)(\\..+)\$/i", $this->infos_docnum["userfile_name"], $matches)) { $nom_tmp = $matches[1] . "_" . $compte . $matches[2]; } else { $nom_tmp = $this->infos_docnum["userfile_name"] . "_" . $compte; } $compte++; } else { if (mysql_num_rows($result)) { //J'ai déjà ce fichier pour cette notice //Je dois enlever l'ancien document numérique pour ne pas l'avoir en double $old_docnum = new explnum(mysql_result($result, 0, 1)); $old_docnum->delete(); } else { } $continue = false; } } while ($continue); if ($compte != 1) { $this->infos_docnum["userfile_name"] = $nom_tmp; if ($upfolder->isHashing()) { $file_name = $rep . $this->infos_docnum["userfile_name"]; } else { $file_name = $upfolder->get_path($this->infos_docnum["userfile_name"]) . $this->infos_docnum["userfile_name"]; } $file_name = $upfolder->encoder_chaine($file_name); } else { } } else { } rename($filename, $file_name); } else { //enregistrement en base $this->infos_docnum["contenu"] = file_get_contents($filename); } $this->params["maj_mimetype"] = true; $this->params["maj_data"] = true; $this->params["maj_vignette"] = true; }