Example #1
0
$photoDao = new PhotoDAO();
$showPhotos = $photoDao->showPhotos();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $photoObj = new Photo();
    if (isset($_POST['is_item'])) {
        $is_item = '1';
    } else {
        $is_item = '0';
    }
    if (isset($_POST['is_photo'])) {
        $is_photo = '1';
    } else {
        $is_photo = '0';
    }
    $photoObj->setID($_POST['id']);
    $photoObj->setDescription($_POST['description']);
    $photoObj->setIsItem($is_item);
    $photoObj->setIsPhoto($is_photo);
    $rowphoto = $photoDao->editOne($photoObj->getId(), $photoObj->getDescription(), $photoObj->getIsItem(), $photoObj->getIsPhoto());
}
?>

<div class="main container-fluid">
    <!--div class="section"-->
        <?php 
while ($row = $showPhotos->fetch_assoc()) {
    ?>
            <div class="secolPhoto">
                <table class="table datagrid" style="width: 25%">
                    <tr style="background-color: chocolate">
                        <th style="width: 25%"><?php 
Example #2
0
 private function setPhotoDescription()
 {
     Module::dependencies(isset($_POST['photoID'], $_POST['description']));
     $photo = new Photo($this->database, $this->plugins, null, $_POST['photoID']);
     echo $photo->setDescription($_POST['description']);
 }
 /**
  * Run method with main page logic
  * 
  * Populate template and display form for creating a new photo entry. For POST request,
  * validate form data and save information to database. Available to admins only
  * @access public
  */
 public function run()
 {
     $session = Session::getInstance();
     $user = $session->getUser();
     if (!$user || !$user->isAdmin()) {
         $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR);
         header("Location: " . BASE_URL);
         return;
     }
     $photoDAO = PhotoDAO::getInstance();
     $albumDAO = AlbumDAO::getInstance();
     $photo = null;
     $form_errors = array();
     $form_values = array("albumid" => "", "title" => "", "description" => "");
     if (!empty($_POST)) {
         $form_values["albumid"] = isset($_POST["albumid"]) && is_numeric($_POST["albumid"]) ? intval($_POST["albumid"]) : "";
         $form_values["title"] = isset($_POST["title"]) ? trim($_POST["title"]) : "";
         $form_values["description"] = isset($_POST["description"]) ? trim($_POST["description"]) : "";
         if (empty($form_values["albumid"])) {
             $form_errors["albumid"] = "No albumid specified";
         } else {
             if (!$albumDAO->load($form_values["albumid"])) {
                 $form_errors["albumid"] = "Album does not exist";
             }
         }
         if (empty($form_values["title"])) {
             $form_errors["title"] = "No title specified";
         }
         if (empty($form_values["description"])) {
             $form_errors["description"] = "No description specified";
         }
         $upload_path = "";
         if (empty($_FILES["imagefile"]) || $_FILES["imagefile"]["error"] == UPLOAD_ERR_NO_FILE) {
             $form_errors["imagefile"] = "No image file chosen";
         } else {
             if ($_FILES["imagefile"]["error"] != UPLOAD_ERR_OK) {
                 $form_errors["imagefile"] = "File upload failed";
             } else {
                 $info = getimagesize($_FILES["imagefile"]["tmp_name"]);
                 $path = pathinfo($_FILES["imagefile"]["name"]);
                 $upload_path = joinPath(Photo::UPLOAD_DIR, strftime("%Y_%m"), basename($_FILES['imagefile']['name']));
                 $thumbLoc = joinPath(Photo::THUMBNAIL_DIR, strftime("%Y_%m"), $path["filename"] . "_thumb.jpg");
                 $smallThumbLoc = joinPath(Photo::THUMBNAIL_DIR, strftime("%Y_%m"), $path["filename"] . "_thumb_small.jpg");
                 if (!$info || !(strtolower($path["extension"]) != ".png" && strtolower($path["extension"]) != ".jpg" && strtolower($path["extension"]) != ".jpeg")) {
                     $form_errors["imagefile"] = "An invalid file was uploaded";
                 } else {
                     if (file_exists($upload_path)) {
                         unlink($upload_path);
                         if (file_exists($thumbLoc)) {
                             unlink($thumbLoc);
                         }
                         if (file_exists($smallThumbLoc)) {
                             unlink($smallThumbLoc);
                         }
                         //$form_errors["imagefile"] = "Filename already exists.  Please choose different name or delete file first";
                     }
                 }
             }
         }
         if (empty($form_errors)) {
             $photo = new Photo();
             $photo->setAlbumId($form_values["albumid"]);
             $photo->setTitle($form_values["title"]);
             $photo->setDescription($form_values["description"]);
             if (!file_exists(dirname($upload_path))) {
                 mkdir(dirname($upload_path));
             }
             if (move_uploaded_file($_FILES["imagefile"]["tmp_name"], $upload_path)) {
                 $photo->setFileLoc($upload_path);
                 // Create thumbnail
                 if ($info[0] > Photo::MAX_WIDTH) {
                     $phpThumb = new phpThumb();
                     $phpThumb->setSourceFilename($photo->getFileLoc());
                     $phpThumb->setParameter('w', Photo::MAX_WIDTH);
                     $phpThumb->setParameter('config_output_format', 'jpeg');
                     if (!file_exists(dirname($thumbLoc))) {
                         mkdir(dirname($thumbLoc));
                     }
                     if ($phpThumb->GenerateThumbnail() && $phpThumb->RenderToFile($thumbLoc)) {
                         $photo->setThumbLoc($thumbLoc);
                         $phpThumb = new phpThumb();
                         $phpThumb->setSourceFilename($photo->getFileLoc());
                         $phpThumb->setParameter('h', Photo::SMALL_THUMB_HEIGHT);
                         $phpThumb->setParameter('config_output_format', 'jpeg');
                         $phpThumb->GenerateThumbnail();
                     } else {
                         if (file_exists($photo->getFileLoc())) {
                             unlink($photo->getFileLoc());
                         }
                         $form_errors["imagefile"] = "Image larger than " . Photo::MAX_WIDTH . "x" . Photo::MAX_HEIGHT . " and thumbnail generation failed";
                     }
                 }
             } else {
                 $form_errors["imagefile"] = "File could not be moved";
             }
             if (empty($form_errors["imagefile"])) {
                 if ($photoDAO->insert($photo)) {
                     $session->setMessage("Photo saved");
                     header("Location: edit_photo.php?id={$photo->getId()}");
                     return;
                 } else {
                     $session->setMessage("Photo not saved");
                 }
             }
         }
     }
     $album_array = $albumDAO->all();
     $this->template->render(array("title" => "Create Photo", "session" => $session, "main_page" => "create_photo_tpl.php", "photo" => $photo, "form_values" => $form_values, "form_errors" => $form_errors, "album_array" => $album_array));
 }
Example #4
0
 /**
  *@Route("/add")
  */
 public function Add(Request $request)
 {
     $message = [];
     $repository = $this->getDoctrine()->getRepository('AppBundle:categories');
     $query = $repository->createQueryBuilder('p')->getQuery();
     $category = $query->getResult();
     $user = $this->get('security.token_storage')->getToken()->getUser();
     $title = $request->get('title');
     $description = $request->get('description');
     $categories = $request->get('categories');
     $image = $request->get('image');
     function is_valid_type($file)
     {
         $valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif", "image/png");
         if (in_array($file['type'], $valid_types)) {
             return 1;
         }
         return 0;
     }
     if (isset($_FILES['image'])) {
         if (!empty($_FILES['image'])) {
             if (is_valid_type($_FILES['image'])) {
                 if (!file_exists($_FILES['image']['name'])) {
                     $extension = strtolower(substr(strrchr($_FILES['image']['name'], '.'), 1));
                     $filename = DFileHelper::getRandomFileName($extension);
                     $target = 'img/' . $filename . '.' . $extension;
                     if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
                         $photo = new Photo();
                         $em = $this->getDoctrine()->getManager();
                         $photo->setUsername($user);
                         $photo->setDescription($description);
                         $photo->setTitle($title);
                         $photo->setCategories($em->getRepository("AppBundle:categories")->find($categories));
                         $photo->setImage('img/' . $filename . '.' . $extension);
                         $em->persist($photo);
                         $em->flush();
                         $message['success'] = "Photo added";
                     } else {
                         $message['danger'] = "You can not download the file. Check permissions to the directory ( read / write)";
                     }
                 } else {
                     $message['danger'] = "File with this name already exists";
                 }
             } else {
                 $message['danger'] = "You can upload files : JPEG, GIF, BMP, PNG";
             }
         }
     }
     $user = $this->get('security.token_storage')->getToken()->getUser();
     if ($user) {
         $repo = $this->getDoctrine()->getManager()->getRepository('AppBundle:photo');
         $qb = $repo->createQueryBuilder('a');
         $qb->select('COUNT(a)');
         $qb->where('a.username = :usernameId');
         $qb->setParameter('usernameId', $user);
         $photos = $qb->getQuery()->getSingleScalarResult();
     }
     return $this->render('site/img_add.html.twig', array('title' => 'Add photo', 'url' => 'add', 'message' => $message, 'photos' => $photos, 'var' => $image, 'category' => $category, 'base_dir' => realpath($this->container->getParameter('kernel.root_dir') . '/..')));
 }
Example #5
0
 private function setPhotoDescription()
 {
     Module::dependencies(isset($_POST['photoID'], $_POST['description']));
     $photo = new Photo(null, $_POST['photoID']);
     echo $photo->setDescription($_POST['description']);
 }
Example #6
0
} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        // ajouter la photo dans le dossier PHOTOS
        echo "L'image " . basename($_FILES["fileToUpload"]["name"]) . " a &eacute;t&eacute; ajout&eacute;. ";
        // Insérer un nouveau enregistrement dans la table PHOTO
        $category = "no category";
        $season = "no season";
        $title = basename($_FILES["fileToUpload"]["name"]);
        $description = "no description";
        $link = $target_file;
        $unePhoto = new Photo();
        //$unePhoto->setId( $_REQUEST['id'] );
        $unePhoto->setCategory($category);
        $unePhoto->setSeason($season);
        $unePhoto->setTitle($title);
        $unePhoto->setDescription($description);
        $unePhoto->setLink($link);
        $unePhoto->setHidden(0);
        $dao = new PhotoDao();
        $dao->create($unePhoto);
    } else {
        echo "D&eacute;sol&eacute;, une erreur s'est produite.";
    }
}
// Source de : http://www.w3schools.com/
?>
		<br/>
		<br/>
		<a href="./admin.php?what=photo"><b><u>Retourner &agrave; la gestion des photos</u></b></a>
		
	</div>