- How to view first picture in a file using php?
- $albums = get_albums();
- if(empty($albums)){
- echo 'No Albums';
- }else{
- foreach($albums as $album){
- echo '<p><a href="view_album.php?album_id=', $album['id'] ,'">', $album['name'],'</a>(', $album['count'], ' images) <br />
- ', $album['description'], '...<br />
- <a href="edit_album.php?album_id=', $album['id'] , '">Edit</a> / <a href="delete_album.php?album_id=', $album['id'] , '">Delete</a>
- </p>';
- }
- }
- function get_albums(){
- $albums = array();
- $albums_query = mysql_query("
- SELECT `albums`.`album_id`, `albums`.`timestamp`, `albums`.`name`, LEFT(`albums`.`description`, 50) as `description`, COUNT(`images`.`image_id`) as `image_count`
- FROM `albums`
- LEFT JOIN `images`
- ON `albums`.`album_id` = `images`.`album_id`
- WHERE `albums`.`user_id` = " . $_SESSION['user_id'] . "
- GROUP BY `albums`.`album_id`
- ");
- while($albums_row = mysql_fetch_assoc($albums_query)){
- $albums[] = array(
- 'id' => $albums_row['album_id'],
- 'timestamp' => $albums_row['timestamp'],
- 'name' => $albums_row['name'],
- 'description' => $albums_row['description'],
- 'count' => $albums_row['image_count']
- );
- }
- return $albums;
- }
- function get_images($album_id){
- $album_id = (int)$album_id;
- $images = array();
- $image_query = mysql_query("SELECT `image_id`, `album_id`, `timestamp`, `ext` FROM `images` WHERE `album_id` = $album_id AND `user_id` = ". $_SESSION['user_id']);
- while($images_row = mysql_fetch_assoc($image_query)){
- $images[] = array(
- 'id' => $images_row['image_id'],
- 'album' => $images_row['album_id'],
- 'timestamp' => $images_row['timestamp'],
- 'ext' => $images_row['ext']
- );
- }
- return $images;
- }
- if(!isset($_GET['album_id']) || empty($_GET['album_id']) || album_check($_GET['album_id']) === false){
- header('Location: albums.php');
- exit();
- }
- $album_id = $_GET['album_id'];
- $album_data = album_data($album_id, 'name');
- echo '<h1 class="logo2">', $album_data['name'], '</h1>';
- include 'includes/menu_album.php';
- $images = get_images($album_id);
- if(empty($images)){
- echo 'No images.';
- }else{
- foreach($images as $image){
- echo '<a href="uploads/', $image['album'], '/', $image['id'], '.', $image['ext'], '"><img src="uploads/thumbs/', $image['album'], '/', $image['id'], '.', $image['ext'], '" title="Uploaded ', date('D M Y', $image['timestamp']), '"></a> [<a href="delete_image.php?image_id=', $image['id'], '">x</a>] ';
- }
- }
- foreach($albums as $album){
- if (empty($album['image'])) {
- $album['image'] = 'default.jpg';
- }
- echo '<p>
- <a href="view_album.php?album_id=', $album['id'] ,'">
- <img src="uploads/thumbs/', $album['id'] ,'/', $album['image'] ,'" />', $album['name'],'
- </a>(', $album['count'], ' images) <br />
- ', $album['description'], '...<br />
- <a href="edit_album.php?album_id=', $album['id'] , '">Edit</a> / <a href="delete_album.php?album_id=', $album['id'] , '">Delete</a>
- </p>';
- }