Error in uploading PHP image

2

Blz Galera

I'm doing an image upload test and the error is appearing:

Notice: Undefined index: photo in C: \ xampp \ htdocs \ cadastro.php on line 2

Notice: Undefined index: photo in C: \ xampp \ htdocs \ cadastro.php on line 3

What's wrong? Thanks in advance.

Obs. The script in index.php is because I have more than one button in the form.

index.php

<form id="cadastro" name="cadastro" method="post">
<input type="file" name="foto" />
<input type="button" value="Cadastrar" onClick="ExecutaAcao('cadastro');">
</form>

<script>
function ExecutaAcao(valor){
document.cadastro.action = valor + '.php';
document.cadastro.submit();
}
</script>

cadastro.php

<?php 
$imagem = $_FILES['foto']['name'];
$tmp_name = $_FILES['foto']['tmp_name'];
$location = "imagens/$imagem";
move_uploaded_file($tmp_name,$location);
?>
    
asked by anonymous 30.01.2018 / 05:09

1 answer

0

Add enctype to your form:

<form id="cadastro" name="cadastro" method="post" enctype="multipart/form-data">

Read more here and here .

    
30.01.2018 / 12:26