public function save($conn = null) { parent::save(); $BASE = $this->URL_IMAGE; $ON = $this->getObject(); if ($ON instanceof Noticies) { $I = $ON->getImatge(); if (!empty($I) && file_exists($BASE . $I)) { $img = new sfImage($BASE . $I, 'image/jpg'); $img->resize(100, 100); $nom = $ON->getIdnoticia() . '.jpg'; $img->saveAs($BASE . $nom); if ($I != $nom) { unlink($BASE . $I); } $ON->setImatge($nom)->save(); } $P = $ON->getAdjunt(); if (!empty($P) && file_exists($BASE . $P)) { $nom = $ON->getIdnoticia() . '.pdf'; rename($BASE . $P, $BASE . $nom); if ($I != $nom) { unlink($BASE . $P); } $ON->setAdjunt($nom)->save(); } } }
public function save($conn = null) { parent::save(); //Si guardem el cicle per primera vegada, mirem les imatges que s'han entrat i que no tenen cicle. Les assignarem a aquest. $dir = getcwd() . '/images/noticies/'; $mini = false; $normal = false; $big = false; $pdf = false; $IDN = $this->getObject()->getIdnoticia(); foreach (glob($dir . 'N--*') as $K => $arxiu) { $a = str_replace($dir, "", $arxiu); //Si té un -M és la foto mini. if (substr_count($arxiu, "-M") > 0) { rename($arxiu, str_replace('--', '-' . $IDN . '-', $arxiu)); } if (substr_count($arxiu, "-L") > 0) { rename($arxiu, str_replace('--', '-' . $IDN . '-', $arxiu)); } if (substr_count($arxiu, "-XL") > 0) { rename($arxiu, str_replace('--', '-' . $IDN . '-', $arxiu)); } if (substr_count($arxiu, "-PDF") > 0) { rename($arxiu, str_replace('--', '-' . $IDN . '-', $arxiu)); } } /* $BASE = $this->URL_IMAGE; $ON = $this->getObject(); if($ON instanceof Noticies): $I = $ON->getImatge(); if(!empty($I) && file_exists($BASE.$I)): $img = new sfImage($BASE.$I,'image/jpg'); $img->resize(100,100); $nom = $ON->getIdnoticia().'.jpg'; $img->saveAs($BASE.$nom); if( $I <> $nom ) unlink($BASE.$I); $ON->setImatge($nom)->save(); endif; $P = $ON->getAdjunt(); if(!empty($P) && file_exists($BASE.$P)): $nom = $ON->getIdnoticia().'.pdf'; rename($BASE.$P,$BASE.$nom); if( $I <> $nom ) unlink($BASE.$P); $ON->setAdjunt($nom)->save(); endif; endif; */ }