Insérer un fichier d'extension pdf mysql

cherni12 Messages postés 1 Date d'inscription dimanche 14 avril 2013 Statut Membre Dernière intervention 8 avril 2014 - 8 avril 2014 à 14:29
NHenry Messages postés 15112 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 13 avril 2024 - 8 avril 2014 à 21:05
Bonjour, je suis en train de faire une page web simple permettant d'insérer un fichier d'extension pdf dans une base de donnée MYSQL , voila le script mais ca marche pas ,
<?php require_once('../Connections/bw.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

if (isset($_FILES['fichier']) AND $_FILES['fichier']['error'] == 0)
{
if ($_FILES['fichier']['size'] <= 1000000)
{
$infosfichier = pathinfo($_FILES['fichier']['name']);
$extension_upload = $infosfichier['extension'];
$extensions_autorisees = array('pdf');
if (in_array($extension_upload, $extensions_autorisees))
{
// On peut valider le fichier et le stocker définitivement
move_uploaded_file($_FILES['fichier']['tmp_name'], 'uploads/' . basename($_FILES['fichier']['name']));
echo "L'envoi a bien été effectué !";
}
}
}

$insertSQL = sprintf("INSERT INTO cours (id_cours, categorie, nom_cours, format, resume_cours, cour) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id_cours'], "int"),
GetSQLValueString($_POST['categorie'], "text"),
GetSQLValueString($_POST['nom_cours'], "text"),
GetSQLValueString($_POST['format'], "text"),
GetSQLValueString($_POST['resume_cours'], "text"),
GetSQLValueString($infosfichier, "text"));

mysql_select_db($database_bw, $bw);
$Result1 = mysql_query($insertSQL, $bw) or die(mysql_error());
}
?>

1 réponse

NHenry Messages postés 15112 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 13 avril 2024 159
8 avril 2014 à 21:05
Bonsoir,

En général, on évite de mettre des fichiers directement dans la base de données, cela a tendance à l'alourdir et la ralentir.
Il est préférable de stocker le fichier en tant que fichier, puis de dire dans la BDD, où il se trouve.
0
Rejoignez-nous