par
lamerehic » 28 juil. 2012, 15:41
merci pour ta réponse,
j'ai fini par réussir l'upload, je crée des thumbnails ensuite et je les stocke dans des dossiers.
Maintenant je veux faire une entrée dans la base.
avec l'id le nom, le titre, etc...
j'ai réécrit le code, j'ai bien l'upload mais j'ai pas d'entrée dans la base.
Code : Tout sélectionner
<?php
include "config.php";
include "database.fn.php";
// ***** ici on récupère les données et on les stocke dans mysql
$nom = $_POST['nom'];
$note = $_POST['note'];
//******* On renomme l'image de manière aléatoire pour éviter un conflit dans le dossier (2 fois le même nom par exemple
include 'functions.php';
$allowed_ext = "jpg, gif, png, jpeg, JPG";
$top = 50;
$filename = $_FILES['image']['name'];
// Is the extension allowed?
$extension = checkext($filename, $allowed_ext);
if ($extension != False)
{
// Move the temporary file to the image folder
$save_to="temp/";
if ($_POST['send_upload']==1)
{
$file_name=$_FILES['image']['name'];
move_uploaded_file($_FILES['image']['tmp_name'], $save_to.basename($file_name)) or die('Cannot upload image');
$filepath = $save_to.basename($file_name);
}
// Create an image resource from the uploaded image
if($extension == "jpg" || $extension == "jpeg" || $extension == "JPG"){
$source=imagecreatefromjpeg($filepath);
}elseif($extension == "png") {
$source=imagecreatefrompng($filepath);
}elseif($extension == "gif") {
$source=imagecreatefromgif($filepath);
}
// Resize the image resource
$width_orig = imagesx( $source ); // width of image resource
$height_orig = imagesy( $source ); // height of image resource
$uploadedimage = $source; // Create space for the resized image
//Save the resized image
if($extension == "jpg" || $extension == "jpeg" || $extension == "JPG"){
imagejpeg($uploadedimage, $filepath, 100);
}elseif($extension == "png") {
imagepng($uploadedimage, $filepath);
}elseif($extension == "gif") {
imagegif($uploadedimage, $filepath);
}
//Print and clean stuff
$im =imagejpeg($uploadedimage, "images/genuine/" . $filename );
//imagedestroy($im);
imagedestroy($uploadedimage);
// imagedestroy($source);
}
$im = imagecreatefromjpeg('images/genuine/'.$filename);
// thumbnail
list($width, $height) = getimagesize('images/genuine/'.$filename);
$new_width = 150;
$new_height = round((150/$width)*$height);
// Redimensionnement
$image_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_p, $im, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_p, 'images/thumbs/'.md5($filename).'-thumb.jpg', 70);
imagedestroy($im);
imagedestroy($image_p);
$link = database_connect($db);
$sql = "SELECT *
FROM poster
WHERE `md5`='".addslashes(md5($filename))."'";
$result = mysql_query($sql, $link)
or die('Erreur MySQL');
if (mysql_num_rows($result)==1)
return md5($filename);
$ip = $_SERVER["REMOTE_ADDR"];
$photo = "../images/genuine/" . $filename;
$md5 = ".addslashes(md5($filename)).";
$model = '';
$title = ".addslashes($filename).";
$today = date("F j, Y, g:i a");
$loc = ".addslashes($ip).";
$warnings = 0;
$candidate = 0;
$accepted = 0;
$date_accepted = 0;
//
echo $title,"</br>", $photo,"</br>", $md5, $loc, $today;
// on enregistre les données
$result = "INSERT INTO poster (id,nom, note, photo, md5, model, title, date, ip, warning, candidate, accepted, date_accepted) VALUES
(
'',
'".mysql_real_escape_string($nom)."',
'".mysql_real_escape_string($note)."',
'".mysql_real_escape_string($photo)."',
'".mysql_real_escape_string($md5)."',
'".mysql_real_escape_string($model)."',
'".mysql_real_escape_string($title)."',
'".mysql_real_escape_string($today)."',
'".mysql_real_escape_string($loc)."',
'".mysql_real_escape_string($warnings)."',
'".mysql_real_escape_string($candidate)."',
'".mysql_real_escape_string($accepted)."',
'".mysql_real_escape_string($date_accepted)."',
)
";
mysql_query($result);
//Si il y a une erreur, on crie ^^
if (!$result) {
die('Requête invalide : ' . mysql_error()); echo"$result";
}
// on ferme la connection mysql donc ci-dessous plus de sql
mysql_close($link);
?>
merci pour ta réponse,
j'ai fini par réussir l'upload, je crée des thumbnails ensuite et je les stocke dans des dossiers.
Maintenant je veux faire une entrée dans la base.
avec l'id le nom, le titre, etc...
j'ai réécrit le code, j'ai bien l'upload mais j'ai pas d'entrée dans la base.
[code]
<?php
include "config.php";
include "database.fn.php";
// ***** ici on récupère les données et on les stocke dans mysql
$nom = $_POST['nom'];
$note = $_POST['note'];
//******* On renomme l'image de manière aléatoire pour éviter un conflit dans le dossier (2 fois le même nom par exemple
include 'functions.php';
$allowed_ext = "jpg, gif, png, jpeg, JPG";
$top = 50;
$filename = $_FILES['image']['name'];
// Is the extension allowed?
$extension = checkext($filename, $allowed_ext);
if ($extension != False)
{
// Move the temporary file to the image folder
$save_to="temp/";
if ($_POST['send_upload']==1)
{
$file_name=$_FILES['image']['name'];
move_uploaded_file($_FILES['image']['tmp_name'], $save_to.basename($file_name)) or die('Cannot upload image');
$filepath = $save_to.basename($file_name);
}
// Create an image resource from the uploaded image
if($extension == "jpg" || $extension == "jpeg" || $extension == "JPG"){
$source=imagecreatefromjpeg($filepath);
}elseif($extension == "png") {
$source=imagecreatefrompng($filepath);
}elseif($extension == "gif") {
$source=imagecreatefromgif($filepath);
}
// Resize the image resource
$width_orig = imagesx( $source ); // width of image resource
$height_orig = imagesy( $source ); // height of image resource
$uploadedimage = $source; // Create space for the resized image
//Save the resized image
if($extension == "jpg" || $extension == "jpeg" || $extension == "JPG"){
imagejpeg($uploadedimage, $filepath, 100);
}elseif($extension == "png") {
imagepng($uploadedimage, $filepath);
}elseif($extension == "gif") {
imagegif($uploadedimage, $filepath);
}
//Print and clean stuff
$im =imagejpeg($uploadedimage, "images/genuine/" . $filename );
//imagedestroy($im);
imagedestroy($uploadedimage);
// imagedestroy($source);
}
$im = imagecreatefromjpeg('images/genuine/'.$filename);
// thumbnail
list($width, $height) = getimagesize('images/genuine/'.$filename);
$new_width = 150;
$new_height = round((150/$width)*$height);
// Redimensionnement
$image_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_p, $im, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_p, 'images/thumbs/'.md5($filename).'-thumb.jpg', 70);
imagedestroy($im);
imagedestroy($image_p);
$link = database_connect($db);
$sql = "SELECT *
FROM poster
WHERE `md5`='".addslashes(md5($filename))."'";
$result = mysql_query($sql, $link)
or die('Erreur MySQL');
if (mysql_num_rows($result)==1)
return md5($filename);
$ip = $_SERVER["REMOTE_ADDR"];
$photo = "../images/genuine/" . $filename;
$md5 = ".addslashes(md5($filename)).";
$model = '';
$title = ".addslashes($filename).";
$today = date("F j, Y, g:i a");
$loc = ".addslashes($ip).";
$warnings = 0;
$candidate = 0;
$accepted = 0;
$date_accepted = 0;
//
echo $title,"</br>", $photo,"</br>", $md5, $loc, $today;
// on enregistre les données
$result = "INSERT INTO poster (id,nom, note, photo, md5, model, title, date, ip, warning, candidate, accepted, date_accepted) VALUES
(
'',
'".mysql_real_escape_string($nom)."',
'".mysql_real_escape_string($note)."',
'".mysql_real_escape_string($photo)."',
'".mysql_real_escape_string($md5)."',
'".mysql_real_escape_string($model)."',
'".mysql_real_escape_string($title)."',
'".mysql_real_escape_string($today)."',
'".mysql_real_escape_string($loc)."',
'".mysql_real_escape_string($warnings)."',
'".mysql_real_escape_string($candidate)."',
'".mysql_real_escape_string($accepted)."',
'".mysql_real_escape_string($date_accepted)."',
)
";
mysql_query($result);
//Si il y a une erreur, on crie ^^
if (!$result) {
die('Requête invalide : ' . mysql_error()); echo"$result";
}
// on ferme la connection mysql donc ci-dessous plus de sql
mysql_close($link);
?>
[/code]