My error Notice: Undefined index: file in C: \ xampp \ htdocs \ zayonet \ start.php on line 99

0

I have a problem with this code below. I have a form in which the user has two options between simply typing text and publishing or text with image. Unfortunately $_FILES["file"] is being identified giving an error similar to:

  

Notice: Undefined index: file in C: \ xampp \ htdocs \ zayonet \ start.php on   line 99

     

Notice: Undefined index: file in C: \ xampp \ htdocs \ zayonet \ start.php on   line 122

     

Notice: Undefined index: file in C: \ xampp \ htdocs \ zayonet \ start.php on   line 123

How can I resolve?

HTML:

  
<div class="col-md-12 col-sm-12 publish">
				
<form action="" method="POST" accept-charset="utf-8" enctype="multipart/form-date">
			        
<textarea name="texto" placeholder="Write anything here"></textarea>
<label for="file-input"><img src="icons/foto1.png" alt="Insert Photo" 
class="maquina-foto"></label>
<input type="submit" name="POSTER" value="Post" />
<input type="file" name="file" id="file-input"  style="display:none;" />

</form>
</div>

PHP:

<?php 
if (isset($_POST['POSTER'])) { 

	$error = $_FILES["file"]["error"];

	if ($error) {
		$texto = $_POST["texto"];
		$date = date("Y-m-d");

		if ($texto == "") {
			echo "You have to write something";
		}else{
			$query_pubs = BD::conn()->prepare("INSERT INTO public ('user' , 'texto' , 'date') VALUES (:e , :t , :d)");
			$query_pubs->bindParam(":e", $_SESSION['email_user']);
			$query_pubs->bindParam(":t", $texto);
			$query_pubs->bindParam(":d", $date);
			$query_pubs->execute();

			if ($query_pubs) {
				echo "<script language='javascript'>window.location='';</script>";
			}else{
				echo "Something did not go well ... Try later.";
			}
		}
	}else{
		$n = rand(0, 1000000);
		$img = $n.$_FILES["file"]["name"];
		$tmp_name=$_FILES["file"]["tmp_name"]; 

		move_uploaded_file($tmp_name, "upload_imagens/".$img);

		$texto = $_POST["texto"];
		$date = date("Y-m-d");
		
		if ($texto == "") {
			echo "You have to write something";
		}else{
			$query_pubs_1 =BD::conn()->prepare("INSERT INTO public ('user' , 'texto' , 'imagem' , 'date') VALUES (:e_1, :t_1, :img, :d_1)");
			$query_pubs_1->bindParam(":e_1", $_SESSION['email_user']);
			$query_pubs_1->bindParam(":t_1", $texto);
			$query_pubs_1->bindParam(":img", $img);
			$query_pubs_1->bindParam(":d_1", $date);
			$query_pubs_1->execute();
			if ($query_pubs_1) {
				//header("Location: ./");
				echo '<script language="javascript">window.location=""</script>';
			}else{
				echo "Something did not go well ... try later. ";
			}
		}
	}

	

}
?>
    
asked by anonymous 09.09.2017 / 10:04

0 answers