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();
}
// }}}
// {{{ 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
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;
}
// }}}