Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.02 KB | None | 0 0
  1. <?php
  2. include("db.php");
  3.  
  4. if (isset($_POST['publicar'])) {
  5.     if ($_FILES["file"]["error"] > 0) {
  6.         $texto = $_POST["texto"];
  7.         $hoje = date("Y-m-d");
  8.  
  9.         if ($texto == "") {
  10.             echo "<h4>Escreva algo antes de publicar</h4>";
  11.         } else {
  12.             $query = "INSERT INTO publicacoes (user, texto, data) VALUES ('$login_cookie', '$texto', '$hoje')";
  13.             $data = mysql_query($query) or die();
  14.             if ($data) {
  15.                 header("Location: ./");
  16.             }else {
  17.                 echo "Algo deu errado, tente novamente!";
  18.             }
  19.          }
  20.       }
  21.     }else {
  22.         $n = rand(0, 1000000);
  23.         $img = $n.$_FILES["file"]["name"];
  24.  
  25.         move_uploaded_file($_FILES["file"]["tmp_name"], "upload/".$img);
  26.  
  27.         $texto = $_POST['texto'];
  28.         $hoje =date("Y-m-d");
  29.  
  30.         if ($texto == "") {
  31.             echo "<h4>Escreva algo antes de publicar</h4>";
  32.         } else {
  33.             $query = "INSERT INTO publicacoes (user, texto, imagem, data) VALUES ('$login_cookie', '$texto', '$img', '$hoje')";
  34.             $data = mysql_query($query) or die();
  35.             if ($data) {
  36.                 header("Location: ./");
  37.             }else {
  38.                 echo "Algo deu errado, tente novamente!";
  39.             }
  40.          }
  41. }
  42. ?>
  43.  
  44. <!DOCTYPE html>
  45.     <?php
  46.         include('header.php');
  47.     ?>
  48. <body>
  49.    <?php
  50.         include("barrasuperior.php");
  51.    ?>
  52.    <div class="publicar">
  53.        <form method="POST" enctype="multipart/form-data">
  54.             <br>
  55.             <textarea name="texto" placeholder="No que você está pensando ?" ></textarea>
  56.              <div class="subtextarea">
  57.                 <label for="file-input">
  58.                 <img src="img/icone_cam.png" title="inserir uma fotografia"/>
  59.                 </label> <br>
  60.                 <input type="submit" value="Publicar" name="publicar">
  61.                 <input type="file" class="arquivo-input" name="file" hidden>    
  62.              </div>
  63.        </form>
  64.    </div>
  65. </body>
  66. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement