HOME


Mini Shell 1.0
DIR: /home/islapiiu/sites/thegarder/admin/
Upload File :
Current File : /home/islapiiu/sites/thegarder/admin/manage-album-photos.php
<?php
include './header.php';
include("../class/resize-class.php");

$msg = "";
$smsg = "";
$emsg = "";

$db = new DB();

if (isset($_POST["main-gal-img"])) {

    $valid_image_check = array("image/gif", "image/jpeg", "image/jpg", "image/png", "image/bmp");
    if (count($_FILES["image"]) > 0) {
        $folderName = "../images/photo-albums/photos/";

        for ($i = 0; $i < count($_FILES["image"]["name"]); $i++) {

            if ($_FILES["image"]["name"][$i] <> "") {

                $image_mime = strtolower(image_type_to_mime_type(exif_imagetype($_FILES["image"]["tmp_name"][$i])));
                // if valid image type then upload
                if (in_array($image_mime, $valid_image_check)) {

                    $ext = explode("/", strtolower($image_mime));
                    $ext = strtolower(end($ext));
                    $filename = rand(10000, 990000) . '_' . time() . '.' . $ext;
                    $filepath = $folderName . $filename;


                    if (!move_uploaded_file($_FILES["image"]["tmp_name"][$i], $filepath)) {
                        $emsg .= "Failed to upload <strong>" . $_FILES["image"]["name"][$i] . "</strong>. <br>";
                        $counter++;
                    } else {


                        ////////////////////////////////////////////////////////////// 
                        $imgSize = getimagesize($filepath);

                        $newSize = calculateResize(900, $imgSize[0], $imgSize[1]);

                        $resizeObj = new resize($filepath);
                        $resizeObj->resizeImage($newSize[0], $newSize[1], 'crop');
                        $resizeObj->saveImage($filepath, 80);

                        ////////////////////////////////////////////////////////////// 

                        $resizeObj2 = new resize($filepath);
                        $resizeObj2->resizeImage(330, 220, 'crop');
                        $resizeObj2->saveImage($folderName . 'thumb/' . $filename, 80);

                        //insert into database starts 
                        try {
                            $query = "INSERT INTO `album-photos` " .
                                    "(`album`, `photo`, `caption`) " .
                                    "VALUES " .
                                    "('" . mysql_real_escape_string($_POST['albumId'])
                                    . "','" . mysql_real_escape_string($filename)
                                    . "','" . mysql_real_escape_string($_POST['caption']) . "')";

                            $result = $db->readQuery($query);

                            if ($result > 0) {
                                // file uplaoded successfully.
                            } else {
                                // failed to insert into database.
                            }
                        } catch (Exception $ex) {
                            $emsg .= "<strong>" . $ex->getMessage() . "</strong>. <br>";
                        }
                        //insert into database ends
                    }
                } else {
                    $emsg .= "<strong>" . $_FILES["image"]["name"][$i] . "</strong> not a valid image. <br>";
                }
            }
        }


        $msg .= (strlen($smsg) > 0) ? successMessage($smsg) : "";
        $msg .= (strlen($emsg) > 0) ? errorMessage($emsg) : "";
    } else {
        $msg = errorMessage("You must upload atleast one file");
    }
}

$id = $_GET['album'];

$gallery = getAlbumPhotosByAlbumId($id);
?>
<link rel="stylesheet" href="css/lightbox.css">

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">Manage Album : <?php echo $_GET['name']; ?></h3>
    </div>
    <div class="panel-body">

        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">Add New Photo</h3>
            </div>
            <div class="panel-body"> 
                <?php echo $msg; ?>   
                <form name="f2" class="form-inline" action="" method="post" enctype="multipart/form-data">  
                    <div class="form-group"> 
                        <input  class="form-control" name="image[]" type="file" required="TRUE">
                    </div>   
                    <div class="form-group"> 
                        <input type="text" class="form-control" name="caption" placeholder="Caption" required="TRUE">
                    </div> 
                    <div class="contents"></div>  
                    <div>
                        <br>
                        <input type="hidden" name="albumId" value="<?php echo $id; ?>">
                        &nbsp;<input type="submit" name="main-gal-img" class="btn btn-info" value="Upload Images" /> 
                    </div>

                </form> 
            </div>
        </div>
        <div class="panel panel-default"> 
            <div class="panel-body">
                <div class="row">
                    <div class="col-sm-12">
                        <?php
                        if (count($gallery) > 0) {
                            foreach ($gallery as $img) {
                                ?>
                                <div class="col-md-3 col-sm-4 col-xs-6 text-center">
                                    <div class="button-bar-img-thum">
                                        <a href="edit-album-photo.php?i=<?php echo $img["id"]; ?>"class="glyphicon glyphicon-edit" id="<?php echo $img["id"]; ?>"></a>
                                        <button class="glyphicon glyphicon-trash text-danger img-delete-album-photo" id="<?php echo $img["photo"]; ?>"></button>
                                    </div>
                                    <a class="example-image-link text-center" href="../images/photo-albums/photos/<?php echo $img["photo"]; ?>" data-lightbox="example-set" data-title="<?php echo $img["caption"]; ?>.">

                                        <img class="example-image img-responsive" src="../images/photo-albums/photos/thumb/<?php echo $img["photo"]; ?>" alt=""/>
                                        <b>
                                            <?php
                                            if (strlen($img["caption"]) > 30) {
                                                echo substr($img["caption"], 0, 30) . '...';
                                            } else {

                                                echo substr($img["caption"], 0, 30);
                                            }
                                            ?>.
                                        </b>
                                    </a>
                                </div>

                                <?php
                            }
                        } else {
                            ?> 
                            <b>No images in the database.</b> 
                        <?php } ?> 

                    </div>
                </div>
            </div>
        </div>
        <div class="panel panel-default"> 
            <div class="panel-body"> 
                <a href="arrange-album-photos.php?album=<?php echo $_GET['album']; ?>&&name=<?php echo $_GET['name']; ?>"  class="btn btn-info" >
                    Sort Photos =>>
                </a>
            </div>
        </div>
    </div>

</div>

<script src="js/lightbox-plus-jquery.min.js"></script>
<script type="text/javascript">
    $('.img-delete-album-photo').click(function (e) {
        var r = confirm("Are you really want delete this picture?....");
        if (r) {
            window.location.replace("delete-album-photo.php?img=" + this.id);
        }
    });
</script>
<?php
include './footer.php';
?>