Advertisement
kazlik

script rand5

Mar 28th, 2012
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.04 KB | None | 0 0
  1. <div id="content">
  2.       <?
  3. function file_extension($filename)
  4. {
  5.     $path_info = pathinfo($filename);
  6.     return $path_info['extension'];
  7. }
  8. if(isset($_GET["i"])){
  9.   $query = "select * from images where FILE = '" . mysql_real_escape_string($_GET["i"]) . "';";
  10.   $result = mysql_query($query) or die("SQL dotaz nešlo provést");
  11.   $num = mysql_num_rows($result);
  12.   if($num == 1){
  13.   $form = false;
  14.   while ($row=mysql_fetch_array($result)){
  15.   echo "<h2>" . $row["NAME"] . "</h2><a href=\"" . $target_path . $row["FILE"] . "\" target=\"_blank\"><img src=\"" . $target_path . $row["FILE"] . "\" style=\"max-width: 600px; max-height: 400px;\"></a><br>";
  16.         ?><table border=0 id="codes">
  17.         <tr><td>Pouze link: </td><td><input type="text" class="code" value='<? echo $adresa . $target_path . $row["FILE"]; ?>'></td></tr>
  18.         <tr><td>HTML kód: </td><td><input type="text" class="code" value='&lt;a href="<? echo $adresa . $target_path . $row["FILE"]; ?>"&gt;&lt;img src="<? echo $adresa . $target_path . $row["FILE"]; ?>"&gt;&lt;/a&gt;'></td></tr>
  19.         <tr><td>BB kód: </td><td><input type="text" class="code" value='[url=<? echo $adresa . $target_path . $row["FILE"]; ?>][img]<? echo $adresa . $target_path . $row["FILE"]; ?>[/img][/url]'></td></tr>
  20.         </table> <?
  21.   }
  22.   }else{
  23.   $form = true;
  24.   echo "<h4>Omlouváme se, ale daný obrázek neexistuje</h4>";
  25.   }
  26. }
  27. if(!isset($_GET["i"])){
  28. if(isset($_POST["send"])){
  29.   switch(file_extension(strtolower($_FILES['file']['name']))){
  30.     case "png":
  31.     case "jpg":
  32.     case "jpeg":
  33.      
  34.       $name = md5(time() . rand());
  35.       $target_path = $target_path . $name . "." . file_extension(basename( $_FILES['file']['name']));
  36.       $url = $name . "." . file_extension(basename( $_FILES['file']['name']));  
  37.       if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
  38.       $query = "insert into images(NAME, FILE, UPLOADED) values('" . mysql_real_escape_string($_FILES['file']['name']) . "','" . mysql_real_escape_string($url) . "', now());";
  39.       $result = mysql_query($query) or die("SQL dotaz nešlo provést");
  40.         echo " Obrázek byl nahrán<br><h2>" . $_FILES['file']['name'] . "</h2><a href=\"" . $target_path . "\" target=\"_blank\"><img src=\"" . $target_path . "\" style=\"max-width: 600px; max-height: 400px;\"></a><br>";
  41.         ?><table border=0 id="codes">
  42.         <tr><td>Pouze link: </td><td><input type="text" class="code" value='<? echo $adresa . $target_path; ?>'></td></tr>
  43.         <tr><td>HTML kód: </td><td><input type="text" class="code" value='&lt;a href="<? echo $adresa . $target_path; ?>"&gt;&lt;img src="<? echo $adresa . $target_path; ?>"&gt;&lt;/a&gt;'></td></tr>
  44.         <tr><td>BB kód: </td><td><input type="text" class="code" value='[url=<? echo $adresa . $target_path; ?>][img]<? echo $adresa . $target_path; ?>[/img][/url]'></td></tr>
  45.         </table>
  46.         <?
  47.         $form = false;
  48.       } else{
  49.         echo "Při nahrávání došlo k chybě, zkuste to prosím znovu";
  50.         $form = true;
  51.       }
  52.     break;
  53.     default:
  54.       echo "Nahrávat se můžou pouze obrázky s příponami .png; .jpg; .jpeg";
  55.       $form = true;    
  56.     break;
  57.   }
  58. }else{
  59. $form = true;
  60. }}
  61.  
  62. if($form == true){
  63.   ?>
  64.           <form action="" enctype="multipart/form-data" method="POST">
  65.           Vyber obrázek<br>
  66.           <input type="file" name="file"><br>
  67.           <input type="hidden" name="MAX_FILE_SIZE" value="30000000">
  68.           <input type="submit" name="send" value="Nahrát">
  69.         </form>
  70. <? } ?>
  71. <h3>Náhodné obrázky</h3>
  72. <?  $query = "select * from images order by rand() limit 5";
  73.   $result = mysql_query($query) or die("SQL dotaz nešlo provést");
  74.   while ($row=mysql_fetch_array($result)){
  75.  ?><a href="<? echo $adresa . "?i=" . $row["FILE"]; ?>"><div style="position: relative; width: 130px; height: 130px; float: left; margin-left: 18px;display: vertical-align: middle; "><img src="screens/<? echo $row["FILE"]; ?>" style="width: 130px; height: 130px;"></div></a>
  76.  <?
  77.  }
  78.  ?>
  79.       </div>      
  80.     </div>
  81.   </body>
  82. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement