cherni12
Messages postés1Date d'inscriptiondimanche 14 avril 2013StatutMembreDernière intervention 8 avril 2014
-
8 avril 2014 à 14:29
NHenry
Messages postés15112Date d'inscriptionvendredi 14 mars 2003StatutModérateurDernière intervention13 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;
}
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());
}
?>
NHenry
Messages postés15112Date d'inscriptionvendredi 14 mars 2003StatutModérateurDernière intervention13 avril 2024159 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.