bonjour tout le monde,
Je dois votre aide pour transférer les informations d'un fichier de téléchargement vers une base de données.
voici la base de donn ées
//Upload_form.php
//Upload_success.php
//connexion.php
Je dois votre aide pour transférer les informations d'un fichier de téléchargement vers une base de données.
voici la base de donn ées
PHP Code:
-- phpMyAdmin SQL Dump
-- version 4.3.11
-- http://www.phpmyadmin.net
--
-- Client : 127.0.0.1
-- Généré le : Ven 17 Novembre 2017 à 21:17
-- Version du serveur : 5.6.24
-- Version de PHP : 5.6.8
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Base de données : `a_test_sylla`
--
-- --------------------------------------------------------
--
-- Structure de la table `test_table_file`
--
CREATE TABLE IF NOT EXISTS `test_table_file` (
`id` int(11) NOT NULL,
`libelle` varchar(100) NOT NULL,
`commentaires` varchar(250) NOT NULL,
`nom_fichier` varchar(200) NOT NULL,
`extension_fichier` varchar(10) NOT NULL,
`taille_fichier` int(11) NOT NULL,
`etat` enum('1','0') NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Index pour les tables exportées
--
--
-- Index pour la table `test_table_file`
--
ALTER TABLE `test_table_file`
ADD KEY `id` (`id`);
--
-- AUTO_INCREMENT pour les tables exportées
--
--
-- AUTO_INCREMENT pour la table `test_table_file`
--
ALTER TABLE `test_table_file`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
PHP Code:
// upload.php
<?php
class Upload extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper(array('form', 'url'));
}
public function index() {
$this->load->view('upload_form', array('error' => ' ' ));
}
public function do_upload() {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = 2500000;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
//insertion depuis la base de donnees
}
else {
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
}
?>//Upload_form.php
PHP Code:
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<tr>
<td>Libelle :</td>
</br>
<td><input type="text" name="libelle" id="libelle" required="required" /><?php echo form_error('libelle');?></td>
</tr></br>
<tr>
<td>Nom Fichier</td></br>
<td><input type="text" name="nom_fichier" id="nom_fichier" required="required"/><?php echo form_error('file_name');?></td>
</tr></br>
<tr>
<td>Extension Fichier</td></br>
<td><input type="text" name="extension_fichier" id="extension_fichier" required="required"/><?php echo form_error('file_type');?></td>
</tr></br>
<tr>
<td>Taille Fichier</td></br>
<td><input type="text" name="taille_fichier" id="taille_fichier" required="required"/><?php echo form_error('file_size');?></td>
</tr></br>
<tr>
<label >Etat:</label><br/>
<select name="etat" id="etat" required="required" />
<option value="1">choisir</option>
<option value="2">inactif</option>
<option value="2">actif</option>
</select>
</tr></br>
<tr>
<td valign="middle">Commentaires</td></br>
<td><textarea name="commentaires" cols="20" rows="2" id="commentaires" ></textarea></td>
</tr></br>
<form action = "" method = "">
<input type = "file" name = "userfile" size = "20" />
<br /><br />
<input type = "submit" value = "upload" />
</form>
</body>
</html>
//Upload_success.php
PHP Code:
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<h3>telechargement reussi!!!</h3>
<ul>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>
<p><?php echo anchor('upload', 'telecharger un autre fichier !'); ?></p>
</body>
</html>
//connexion.php
PHP Code:
<?php
{
$db=@mysql_connect("localhost","root","")or die(mysql_error());
@mysql_select_db("a_test_sylla",$db);//or ("pb db");
}
?>