-
Notifications
You must be signed in to change notification settings - Fork 0
/
saveimage.php
70 lines (67 loc) · 2.09 KB
/
saveimage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
session_start ();
function add_image_to_table($img_nom, $img_taille, $img_type, $user_login)
{
require 'config/setup.php';
try
{
$stmt = $db_con->prepare("INSERT INTO images(img_nom,img_taille,img_type,user_login) VALUES(:img_nom, :img_taille, :img_type, :user_login)");
$val = $stmt->execute(array(":img_nom"=>$img_nom, ":img_taille"=>$img_taille,":img_type"=>$img_type,":user_login"=>$user_login));
if($val)
$_SESSION['error'] = 'Upload effectué avec succès !';
else
$_SESSION['error'] = 'Echec de l\'upload !';
}
catch(PDOException $e){
echo $e->getMessage();
}
}
function verifname($img_nom)
{
require 'config/setup.php';
try
{
$stmt = $db_con->prepare("SELECT * FROM images WHERE img_nom=:img_nom");
$stmt->execute(array(":img_nom"=>$img_nom));
$count = $stmt->rowCount();
if($count == 0)
return($img_nom);
else
return(verifname("1".$img_nom));
}
catch(PDOException $e){
echo $e->getMessage();
}
}
function transfert()
{
ini_set('upload-max-filesize', '10M');
ini_set('post_max_size', '10M');
$name = $_FILES['fic']['name'];
$dossier = 'tmp_img/';
$extensions = array('.png','.PNG', '.jpg','.JPG', '.jpeg');
$extension = strrchr($name, '.');
if(!in_array($extension, $extensions))
$_SESSION['error'] = "Vous devez uploader un fichier de type png, gif, jpg, jpeg, txt ou doc...";
else if (strpos($name, ' ') != FALSE)
$_SESSION['error'] = "Nom de l'image incorect";
else
{
$name = "img_tmp.png";
$fichier = basename($name);
if(move_uploaded_file($_FILES['fic']['tmp_name'], $dossier . $fichier))
{
// add_image_to_table($name, "10000", $extension, $_SESSION['login']);
$_SESSION['error'] = 'Image uploadé!';
}
else
$_SESSION['error'] = 'Echec de l\'upload !';
}
header('Location: index.php');
}
if (isset($_FILES['fic']['name']))
{
transfert();
$_SESSION['upload'] = "ok";
}
?>