duanshang9426 2012-03-03 17:51
浏览 29
已采纳

创建用户特定的Gallery区域PHP?

Some please help me with coding the below piece!

So at the moment I have a place where members can set up a profile that displays all there information. I now want to give the user an option to upload images. and have a personal Gallery area.

All the tutorials i seem to find only show me how to do an image upload. And not specific to users that there gallery area will have other peoples work in it.

I assume this will need a database to make it user specific? or work off the $_SESSION variable? I just dont know how to go about doing this.

im totally lost can someone point me in the right direction?

Below is my current gallery.php code which just pretty much generates thumbnails and displays all given images in the uploads folder.

How would I go about editing this just to display images for the user in a session or given user profile?

    <?php
if (isset($_GET['img'])){
    //make thumbnail
    if(file_exists($_GET['img'])){
        ignore_user_abort(true);
        set_time_limit(120);
        ini_set('memory_limit', '512M');

        $src_size = getimagesize($_GET['img']);

        if ($src_size === false){
            die('That does not look like an image.');
        }

        $thumb_width    = 200;
        $thumb_height   = 150;

        if ($src_size['mime'] === 'image/jpeg'){
            $src = imagecreatefromjpeg($_GET['img']);
        }else if ($src_size['mime'] === 'image/png'){
            $src = imagecreatefrompng($_GET['img']);
        }else if ($src_size['mime'] === 'image/gif'){
            $src = imagecreatefromgif($_GET['img']);
        }

        $src_aspect = round (($src_size[0] / $src_size[1]), 1);
        $thumb_aspect = round(($thumb_width / $thumb_height), 1);

        if ($src_aspect < $thumb_aspect){
            //higher than thumb
            $new_size = array ($thumb_width, ($thumb_width / $src_size[0]) * $src_size[1]);
            $src_pos = array (0, (($new_size[1] - $thumb_height) * ($src_size[1] / $new_size[1])) / 2);
        }else if ($src_aspect > $thumb_aspect){
            // wider than thumb
            $new_size = array(($thumb_width / $src_size[1] ) * $src_size[0], $thumb_height);
            $src_pos = array((($new_size[0] - $thumb_width) * ($src_size[0] / $new_size[0])) / 2, 0);
        }else{
            // same shape as thumb
            $new_size = array($thumb_width, $thumb_height);
            $src_pos = array(0, 0);
        }

        if ($new_size[0] < 1) $new_size[0] = 1;
        if ($new_size[1] < 1) $new_size[1] = 1;

        $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
        imagecopyresampled($thumb, $src, 0, 0, $src_pos[0], $src_pos[1], $new_size[0], $new_size[1], $src_size[0], $src_size[1]);

        if ($src_size['mime'] === 'image/jpeg'){
            imagejpeg($thumb, "thumbs/{$_GET[ 'img' ]}");
        }else if ($src_size['mime'] === 'image/png'){
            imagepng($thumb, "thumbs/{$_GET[ 'img' ]}");
        }else if ($src_size['mime'] === 'image/gif'){
            imagegif($thumb, "thumbs/{$_GET[ 'img' ]}");
        }

        header("Location: thumbs/{$_GET[ 'img' ]}");
    }

    die();
}

if (is_dir('./thumbs') === false){
    mkdir('./thumbs', 0744);
}

$images = glob('*.{jpg, jpeg, png, gif}', GLOB_BRACE);

?>

            <?php

            foreach ($images as $image){
                if (file_exists("./thumbs/{image}")){
                    echo "<a href=\"{$image}\"><img src=\"thumbs/{$image}\" alt=\"{$image}\" /></a>";
                }else{
                    echo "<a href=\"{$image}\"><img src=\"?img={$image}\" alt=\"{$image}\" /></a>";

                }
            }

            ?>
  • 写回答

1条回答 默认 最新

  • douqiang5163 2012-03-03 17:57
    关注

    I have one suggestion for you.
    Create one table for "Gallery" and insert data about image name and also user_id and this user_id will be id of logged user and that you can fetch from session when specific user is logged in. This is the way you can manage your image gallery with specific user is logged in. Let me know if you need more help.. Cheers

    <?php
       $uid = $_SESSION['uid'];
       $query = mysql_query("SELECT * FROM images WHERE user_id=".$uid);
     ?>
    

    Here, you can use above result set for display images for specific user only.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加