From: Pierre Habouzit (MadCoder Date: Thu, 6 Jan 2005 18:55:36 +0000 (+0000) Subject: correct the photo problem, using the var:// stream X-Git-Tag: xorg/old~528 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=cf6e00ef1b1ed5a8932cc24046ca4a1cbdd59fdb;p=platal.git correct the photo problem, using the var:// stream Patches applied: * opensource@polytechnique.org--2005/platal--release--0.9.3--patch-20 backport from DEV * opensource@polytechnique.org--2005/platal--release--0.9.3--patch-21 corrects the photo problem error * opensource@polytechnique.org--2005/platal--release--0.9.3--patch-22 oops * opensource@polytechnique.org--2005/platal--release--0.9.3--patch-23 re oops. git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-222 --- diff --git a/htdocs/trombino.php b/htdocs/trombino.php index d10c1ab..b8e6ffe 100644 --- a/htdocs/trombino.php +++ b/htdocs/trombino.php @@ -24,32 +24,25 @@ new_skinned_page('trombino.tpl', AUTH_MDP); require_once('validations.inc.php'); -if (Env::has('ordi') and - isset($_FILES['userfile']) and isset($_FILES['userfile']['tmp_name'])) { - //Fichier en local - $myphoto = new PhotoReq(Session::getInt('uid'), $_FILES['userfile']['tmp_name']); - $myphoto->submit(); +if (Env::has('ordi') and isset($_FILES['userfile']['tmp_name'])) { + $data = file_get_contents($_FILES['userfile']['tmp_name']); + if ($myphoto = new PhotoReq(Session::getInt('uid'), $data)) { + $myphoto->submit(); + } } elseif (Env::has('web') and Env::has('photo')) { // net - $fp = fopen(Env::get('photo'), 'r'); - if (!$fp) { - $page->trig('Fichier inexistant'); + if ($s = file_get_contents(Env::get('photo'))) { + if ($myphoto = new PhotoReq(Session::getInt('uid'), $s)) { + $myphoto->submit(); + } } else { - $attach = fread($fp, 35000); - fclose($fp); - $file = tempnam('/tmp','photo_'); - $fp = fopen($file,'w'); - fwrite($fp, $attach); - fclose($fp); - - $myphoto = new PhotoReq(Session::getInt('uid'), $file); - $myphoto->submit(); + $page->trig('Fichier inexistant ou vide'); } } elseif (Env::has('trombi')) { // Fichier à récupérer dans les archives trombi + commit immédiat $file = '/home/web/trombino/photos'.Session::get('promo').'/'.Session::get('forlife').'.jpg'; - $myphoto = new PhotoReq(Session::getInt('uid'), $file); - if($myphoto){// There was no errors, we can go on + $myphoto = new PhotoReq(Session::getInt('uid'), file_get_contents($file)); + if ($myphoto) {// There was no errors, we can go on $myphoto->commit(); $myphoto->clean(); } diff --git a/include/validations/photos.inc.php b/include/validations/photos.inc.php index d6768fa..e1b894b 100644 --- a/include/validations/photos.inc.php +++ b/include/validations/photos.inc.php @@ -33,21 +33,21 @@ class PhotoReq extends Validate // }}} // {{{ constructor - function PhotoReq($_uid, $_file, $_stamp=0) + function PhotoReq($_uid, $_data, $_stamp=0) { - global $erreur, $globals; + global $globals, $page; $this->Validate($_uid, true, 'photo', $_stamp); - if (!file_exists($_file)) { - $erreur = "Fichier inexistant"; - return false; - } // calcul de la taille de l'image - $image_infos = getimagesize($_file); + require_once('xorg.varstream.inc.php'); + $GLOBALS['photoreq'] = $_data; + $image_infos = getimagesize('var://photoreq'); + unset ($GLOBALS['photoreq']); + if (empty($image_infos)) { - $erreur = "Image invalide"; - return false; + $page->trig("Image invalide"); + return ($this = null); } list($this->x, $this->y, $this->mimetype) = $image_infos; // récupération du type de l'image @@ -65,20 +65,15 @@ class PhotoReq extends Validate break; default: - $erreur = "Type d'image invalide"; - return false; + $page->trig("Type d'image invalide"); + return ($this = null); } - // lecture du fichier - if (!($size = filesize($_file)) or $size > SIZE_MAX) { - $erreur = "Image trop grande (max 30ko)"; - return false; - } - $fd = fopen($_file, 'r'); - if (!$fd) return false; - $this->data = fread($fd, SIZE_MAX); - fclose($fd); - unset($erreur); + if (strlen($_data) > SIZE_MAX) { + $page->trig("Image trop grande (max 30ko)"); + return ($this = null); + } + $this->data = $_data; } // }}}