Page 1 sur 2
probleme session avec firefox
Posté : 01 juin 2010, 09:55
par slash33
Bonjour,
voilà je m'arrache les cheveux depuis 3 jours, et je vous demande de l'aide svp.
j'ai un script qui charge une image et la met dans une base de données, tout marche sur iexplorer, mais sur firefox il met 0 dans la base de données dans le champ id_annonce. voilà le code
<?php
session_start();
$ads=$_SESSION["add"];
echo $ads;
require_once('connect.php');
require_once('image.php');
ini_set('mem_size', 32000);
if($_FILES['file']['tmp_name']!=""){
$file_temp = $_FILES['file']['tmp_name'];
$file_name = $_FILES['file']['name'];
chmod("/homez.34/toto/www/photos/",0777);
$dir ="/homez.34/toto/www/photos/";
$nom ="photo";
$nom .= rand();
$nom .= ".png";
$file = $dir.$nom;
$image = new imageResizer($_FILES['file']['tmp_name']);
$image->resize(400, 400, 400, 100);
$image->save("".$file."", PNG);
$queryp = "INSERT INTO `toto`.`photos`(`id`,`id_annonce`,`photo`) VALUES('','$ads', '$nom');";
$resultp = mysql_query($queryp);
echo "success";
$image = null;
}
?>
ce qui est bizzar c que sur firefox il m'affiche bien la session quand je fait un echo.
merci pour votre aide
Re: probleme session avec firefox
Posté : 01 juin 2010, 10:08
par stealth35
apres ton session_start() fait un print_r($_SESSION);
Re: probleme session avec firefox
Posté : 01 juin 2010, 10:11
par slash33
Merci pour la réponse.
le print_r me retourne ça : Array ( [add] => 107 )
Re: probleme session avec firefox
Posté : 01 juin 2010, 10:14
par stealth35
a la place de
$resultp = mysql_query($queryp);
tu fais
echo $queryp;
$resultp = mysql_query($queryp) or exit($queryp . <br /> . mysql_error());
Re: probleme session avec firefox
Posté : 01 juin 2010, 10:25
par slash33
alors j'ai tester ce script seule
<?php
session_start();
$ads=$_SESSION["add"];
echo $ads;
require_once('connect.php');
$nom ="photo";
$nom .= rand();
$nom .= ".png";
$queryp = "INSERT INTO `toto`.`photos`(`id`,`id_annonce`,`photo`) VALUES('','".$ads."', '".$nom."');";
echo $queryp;
$resultp = mysql_query($queryp) or exit(mysql_error());
?>
marche nikel, je crois que le probleme viens lors de l'upload de l'image.
Re: probleme session avec firefox
Posté : 01 juin 2010, 10:41
par slash33
vous croyez que le traitement de l'image peut influencer la session?
Re: probleme session avec firefox
Posté : 01 juin 2010, 10:44
par stealth35
je sais pas elle viens d'ou ta class ?
Re: probleme session avec firefox
Posté : 01 juin 2010, 10:46
par slash33
alors j'appel le script suivant

image.php)
<?php
/*
PHP image resizer
=============
made by Martin Withaar
e: [email protected]
w: www.martienus.com
*/
define("JPG", 0);
define("GIF", 1);
define("PNG", 2);
define("BMP", 3);
define("JPG_QUALITY", 100);
define("PNG_QUALITY", 0);
class imageResizer
{
private $filename;
private $image;
private $data;
private $copy;
function imageResizer($filename) {
if(!is_file($filename))
throw new Exception("File does not exist");
$this->filename = $filename;
$this->data = getimagesize($this->filename);
switch($this->data['mime']) {
case 'image/pjpeg' :
case 'image/jpeg' : $this->image = imagecreatefromjpeg($this->filename); break;
case 'image/gif' : $this->image = imagecreatefromgif($this->filename); break;
case 'image/png' : $this->image = imagecreatefrompng($this->filename); break;
case 'image/x-ms-bmp' : $this->image = imagecreatefromwbmp($this->filename); break;
default : throw new Exception("File format is not supported"); break;
}
}
// Makes a plain copy of the original
public function duplicate() {
if(!isset($this->image))
throw new Exception("No image loaded");
$this->copy = $this->image;
}
// Makes a resized copy of the original
public function resize($wx, $hx, $wm = 0, $hm = 0) {
if(!isset($this->image))
throw new Exception("No image loaded");
if($wx != $wm && $hx != $hm && $wm != 0 && $hm != 0)
throw new Exception("Bad dimensions specified");
$r = $this->data[0] / $this->data[1];
$rx = $wx / $hx;
if($wm == 0 || $hm == 0)
$rm = $rx;
else
$rm = $wm / $hm;
$dx=0; $dy=0; $sx=0; $sy=0; $dw=0; $dh=0; $sw=0; $sh=0; $w=0; $h=0;
if($r > $rx && $r > $rm) {
$w = $wx;
$h = $hx;
$sw = $this->data[1] * $rx;
$sh = $this->data[1];
$sx = ($this->data[0] - $sw) / 2;
$dw = $wx;
$dh = $hx;
} elseif($r < $rm && $r < $rx) {
$w = $wx;
$h = $hx;
$sh = $this->data[0] / $rx;
$sy = ($this->data[1] - $sh) / 2;
$sw = $this->data[0];
$dw = $wx;
$dh = $hx;
} elseif($r >= $rx && $r <= $rm) {
$w = $wx;
$h = $wx / $r;
$dw = $wx;
$dh = $wx / $r;
$sw = $this->data[0];
$sh = $this->data[1];
} elseif($r <= $rx && $r >= $rm) {
$w = $hx * $r;
$h = $hx;
$dw = $hx * $r;
$dh = $hx;
$sw = $this->data[0];
$sh = $this->data[1];
} else {
throw new Exception("Can't resize the image");
}
$this->copy = imagecreatetruecolor($w, $h);
imagecopyresampled($this->copy, $this->image, $dx, $dy, $sx, $sy, $dw, $dh, $sw, $sh);
return true;
}
// Save copy to file. If no file name omitted it will overwrite the original
public function save($filename = false, $type = JPG) {
if(!isset($this->copy))
throw new Exception("No copy to save");
if(!$filename)
$filename = $this->filename;
switch($type) {
case GIF : imagegif($this->copy, $filename); return true; break;
case PNG : imagepng($this->copy, $filename, PNG_QUALITY); return true; break;
case BMP : imagewbmp($this->copy, $filename); return true; break;
case JPG :
default : imagejpeg($this->copy, $filename, JPG_QUALITY); return true; break;
}
//throw new Exception("Save failed");
}
// Save copy to string and return it
public function getString($type = JPG) {
if(!isset($this->copy))
throw new Exception("No copy to return");
$contents = ob_get_contents();
if ($contents !== false) ob_clean();
else ob_start();
$this->show($type);
$data = ob_get_contents();
if ($contents !== false) {
ob_clean();
echo $contents;
}
else ob_end_clean();
return $data;
}
// Output copy to browser
public function show($type = JPG) {
if(!isset($this->copy))
throw new Exception("No copy to show");
switch($type) {
case GIF : imagegif($this->copy, null); return true; break;
case PNG : imagepng($this->copy, null, PNG_QUALITY); return true; break;
case BMP : imagewbmp($this->copy, null); return true; break;
case JPG :
default : imagejpeg($this->copy, null, JPG_QUALITY); return true; break;
}
throw new Exception("Show failed");
}
public function __destruct()
{
imagedestroy($this->image);
imagedestroy($this->copy);
$this->filename = null;
$this->data = null;
}
}
?>
Re: probleme session avec firefox
Posté : 01 juin 2010, 10:48
par stealth35
remet ton resize, pour voir, ca que ca donne la requête SQL
Re: probleme session avec firefox
Posté : 01 juin 2010, 10:51
par slash33
j'ai remis, pareil même probleme il me fou un 0 au lieu de la valeur de la session, je ne comprend pas, j'ai essayer sur une autre machine même probleme.
Re: probleme session avec firefox
Posté : 01 juin 2010, 10:58
par slash33
juste un detail, je suis sur firefox 3.6.3, si ça peut donner des idées.
Re: probleme session avec firefox
Posté : 01 juin 2010, 11:05
par stealth35
j'ai remis, pareil même probleme il me fou un 0 au lieu de la valeur de la session, je ne comprend pas, j'ai essayer sur une autre machine même probleme.
ton code te rend quoi ?
Re: probleme session avec firefox
Posté : 01 juin 2010, 11:10
par slash33
mon code ne me rend pas d'erreur
Re: probleme session avec firefox
Posté : 01 juin 2010, 11:20
par stealth35
mon code ne me rend pas d'erreur
c'est qu'il fait pas la condition
Re: probleme session avec firefox
Posté : 01 juin 2010, 11:25
par slash33
bah si, puisque l'image est redimentionnée et charger sur le serveur, et puis la table est alimenté après, c juste que ce foutu 0 je ne sais pas d'où il me le sort.