Nicketick

Untitled

Sep 30th, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.13 KB | None | 0 0
  1. <?php
  2. $continue = '';
  3. $sessiontekst = md5(date("d-m-Y"));
  4. $sessionname = "Secure";
  5. if(!isset($_SESSION[$sessionname]) or $_SESSION[$sessionname] != $sessiontekst)
  6. {
  7.     $continue = 'Please log in to access this page';
  8. }
  9. if($continue == '') {
  10.     include("config.inc.php");
  11.     include("list.inc.php");
  12.     if($_POST['submit'] == "Submit") {
  13.         // List of our known photo types
  14.         $known_photo_types = array(
  15.             'image/pjpeg' => 'jpg',
  16.             'image/jpeg' => 'jpg',
  17.             'image/gif' => 'gif',
  18.             'image/bmp' => 'bmp',
  19.             'image/x-png' => 'png'
  20.         );
  21.  
  22.         // GD Function List
  23.         $gd_function_suffix = array(
  24.             'image/pjpeg' => 'JPEG',
  25.             'image/jpeg' => 'JPEG',
  26.             'image/gif' => 'GIF',
  27.             'image/bmp' => 'WBMP',
  28.             'image/x-png' => 'PNG'
  29.         );
  30.         // Fetch the cover
  31.         $cover = $_FILES['cover'];
  32.  
  33.         if($cover['size'] > 0)
  34.         {
  35.             if(!array_key_exists($cover['type'], $known_photo_types))
  36.             {
  37.                 $result_final .= "File is not a photo<br />";
  38.             }
  39.             else
  40.             {
  41.                 mysql_query( "INSERT INTO albums(`title`, `type`, `size`, `artist`, `year`, `persing`, `quality`, `colour`, `code`, `label`, `amount`, `comments`, `cover`) VALUES('".$_POST['title']."', '".$_POST['type']."', '".$_POST['size']."', '".$_POST['artist']."', '".$_POST['year']."', '".$_POST['persing']."', '".$_POST['quality']."', '".$_POST['colour']."', '".$_POST['code']."', '".$_POST['label']."', '".$_POST['comments']."', '0')" );
  42.                 $new_id = mysql_insert_id();
  43.                 $filetype = $cover['type'];
  44.                 $extention = $known_photo_types[$filetype];
  45.                 $filename = $new_id.".".$extention;
  46.  
  47.                 mysql_query( "UPDATE albums SET cover='".addslashes($filename)."' WHERE id='".addslashes($new_id)."'" );
  48.  
  49.                 // Store the orignal file
  50.                 copy($photos_uploaded['tmp_name'], $images_dir."/".$filename);
  51.  
  52.                 // Let's get the Thumbnail size
  53.                 $size = getimagesize( $images_dir."/".$filename );
  54.                 if($size[0] > $size[1])
  55.                 {
  56.                     $thumbnail_width = 150;
  57.                     $thumbnail_height = (int)(150 * $size[1] / $size[0]);
  58.                 }
  59.                 else
  60.                 {
  61.                     $thumbnail_width = (int)(150 * $size[0] / $size[1]);
  62.                     $thumbnail_height = 150;
  63.                 }
  64.  
  65.                 // Build Thumbnail with GD 1.x.x, you can use the other described methods too
  66.                 $function_suffix = $gd_function_suffix[$filetype];
  67.                 $function_to_read = "ImageCreateFrom".$function_suffix;
  68.                 $function_to_write = "Image".$function_suffix;
  69.  
  70.                 // Read the source file
  71.                 $source_handle = $function_to_read ( $images_dir."/".$filename );
  72.  
  73.                 if($source_handle)
  74.                 {
  75.                     // Let's create an blank image for the thumbnail
  76.                     $destination_handle = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
  77.  
  78.                     // Now we resize it
  79.                     imagecopyresampled( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1] );
  80.                 }
  81.  
  82.                 // Let's save the thumbnail
  83.                 $function_to_write( $destination_handle, $images_dir."/tb_".$filename );
  84.  
  85.                 //
  86.  
  87.                 echo "Album is added.";
  88.             }
  89.         }
  90.         }
  91.     else {
  92. ?>
  93. <form id="addalbum" method="post">
  94. <select name="artist">
  95. <option disabled="true" selected="true">Artist</option>
  96. <?php echo $artist; ?></select><br>
  97. <input type="text" name="title" placeholder="Title"><br>
  98. <select name="type">
  99. <option disabled="true" selected="true">Type</option>
  100. <?php echo $type; ?></select><br>
  101. <select name="size">
  102. <option disabled="true" selected="true">Size</option>
  103. <?php echo $size; ?></select><br>
  104. <select name="year">
  105. <option disabled="true" selected="true">Year</option>
  106. <?php echo $year; ?></select><br>
  107. <input type="text" name="pressing" placeholder="Pressing"><br>
  108. <select name="quality">
  109. <option disabled="true" selected="true">Quality</option>
  110. <?php echo $quality; ?></select><br>
  111. <select name="colour">
  112. <option disabled="true" selected="true">Colour</option>
  113. <?php echo $colour; ?></select><br>
  114. <input type="text" name="code" placeholder="Code"><br>
  115. <select name="label">
  116. <option disabled="true" selected="true">Label</option>
  117. <?php echo $label; ?></select><br>
  118. <select name="amount">
  119. <option disabled="true" selected="true">Amount</option>
  120. <?php echo $amount; ?></select><br>
  121. <textarea name="comments" placeholder="Comments">
  122. </textarea><br>
  123. <input type="file" name="cover"><br>
  124. <input type="submit" name="submit" value="Submit">
  125. </form>
  126. <?php
  127.     }
  128. }
  129. else {
  130.     echo $continue;
  131. }
  132. ?>
Advertisement
Add Comment
Please, Sign In to add comment