有些人请帮我编码下面的片段!
因此,目前我有一个地方,会员可以在那里建立一个显示所有信息的个人资料。我现在想给用户一个上传图像的选项。还有一个私人画廊区。
我找到的所有教程似乎都只向我展示了如何上传图像。并不是特定的用户,那里的画廊区域将有其他人在其中工作。
我认为这将需要一个数据库来使其特定于用户?或者去掉$_SESSION变量?我只是不知道该怎么做。
我完全迷路了,有人能给我指个正确的方向吗?
下面是我当前的gallery.php代码,它几乎只生成缩略图并在上传文件夹中显示所有给定的图像。
我该如何编辑它,以便在会话或给定的用户配置文件中为用户显示图像?
<?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>";
}
}
?>
我有一个建议给你
为"多媒体资料"创建一个表格并插入关于图像名称以及user_id和该user_id的数据将是已登录用户的id,并且您可以在特定用户已登录。这是管理图像的方法具有特定用户的图库已登录。如果您需要更多信息,请告诉我帮助干杯
<?php
$uid = $_SESSION['uid'];
$query = mysql_query("SELECT * FROM images WHERE user_id=".$uid);
?>
在这里,您可以使用上面的结果集,只显示特定用户的图像。