Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 6th, 2012  |  syntax: None  |  size: 3.00 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to view first picture in a file using php?
  2. $albums = get_albums();
  3.  
  4. if(empty($albums)){
  5. echo 'No Albums';
  6. }else{
  7.  
  8. foreach($albums as $album){
  9.     echo '<p><a href="view_album.php?album_id=', $album['id'] ,'">', $album['name'],'</a>(', $album['count'], ' images) <br />
  10.     ', $album['description'], '...<br />
  11.     <a href="edit_album.php?album_id=', $album['id'] , '">Edit</a> / <a href="delete_album.php?album_id=', $album['id'] , '">Delete</a>
  12.     </p>';
  13. }
  14. }
  15.        
  16. function get_albums(){
  17. $albums = array();
  18.  
  19. $albums_query = mysql_query("
  20. SELECT `albums`.`album_id`, `albums`.`timestamp`, `albums`.`name`, LEFT(`albums`.`description`, 50) as `description`, COUNT(`images`.`image_id`) as `image_count`
  21. FROM `albums`
  22. LEFT JOIN `images`
  23. ON `albums`.`album_id` = `images`.`album_id`
  24. WHERE `albums`.`user_id` = " . $_SESSION['user_id'] . "
  25. GROUP BY `albums`.`album_id`
  26. ");
  27.  
  28. while($albums_row = mysql_fetch_assoc($albums_query)){
  29.     $albums[] = array(
  30.         'id'            => $albums_row['album_id'],
  31.         'timestamp'     => $albums_row['timestamp'],
  32.         'name'          => $albums_row['name'],
  33.         'description'   => $albums_row['description'],
  34.         'count'         => $albums_row['image_count']
  35.     );
  36. }
  37.  
  38. return $albums;
  39.  
  40. }
  41.        
  42. function get_images($album_id){
  43. $album_id = (int)$album_id;
  44.  
  45. $images = array();
  46.  
  47. $image_query = mysql_query("SELECT `image_id`, `album_id`, `timestamp`, `ext` FROM `images` WHERE `album_id` = $album_id AND `user_id` = ". $_SESSION['user_id']);
  48. while($images_row = mysql_fetch_assoc($image_query)){
  49.     $images[] = array(
  50.         'id'            => $images_row['image_id'],
  51.         'album'         => $images_row['album_id'],
  52.         'timestamp'     => $images_row['timestamp'],
  53.         'ext'           => $images_row['ext']
  54.     );
  55. }
  56. return $images;
  57. }
  58.        
  59. if(!isset($_GET['album_id']) || empty($_GET['album_id']) || album_check($_GET['album_id']) === false){
  60. header('Location: albums.php');
  61. exit();
  62. }
  63.  
  64. $album_id = $_GET['album_id'];
  65. $album_data = album_data($album_id, 'name');
  66.  
  67. echo '<h1 class="logo2">', $album_data['name'], '</h1>';
  68. include 'includes/menu_album.php';
  69.  
  70. $images = get_images($album_id);
  71.  
  72. if(empty($images)){
  73. echo 'No images.';
  74. }else{
  75. foreach($images as $image){
  76.     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>] ';
  77. }
  78. }
  79.        
  80. foreach($albums as $album){
  81.     if (empty($album['image'])) {
  82.         $album['image'] = 'default.jpg';
  83.     }
  84.     echo '<p>
  85.       <a href="view_album.php?album_id=', $album['id'] ,'">
  86.         <img src="uploads/thumbs/', $album['id'] ,'/', $album['image'] ,'" />', $album['name'],'
  87.       </a>(', $album['count'], ' images) <br />
  88.       ', $album['description'], '...<br />
  89.       <a href="edit_album.php?album_id=', $album['id'] , '">Edit</a> / <a href="delete_album.php?album_id=', $album['id'] , '">Delete</a>
  90.     </p>';
  91. }