Input file nao repassa nome de arquivo
Olá, amigos do iMasters!
Estou precisando de uma mãozinha no código abaixo:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Guitar Wars - Add Your High Score</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h2>Batalha das guitarras - Adicione seu recorde</h2>
<?php
// define as constantes do caminho e do tamanho maximo dos arquivos
define('GW_UPLOADPATH', 'images/');
if (isset($_POST['submit'])) {
// Grab the score data from the POST
$name = $_POST['name'];
$score = $_POST['score'];
$screenshot = $_POST['screenshot'];
if (!empty($name) && !empty($score) && !empty($screenshot)) {
// move a imagem para a pasta alvo
$target = GW_UPLOADPATH.$screenshot;
echo $target;
if (move_uploaded_file($_FILES['screenshot']['tmp_name'],$target))
// Connect to the database
$dbc = mysqli_connect('localhost', 'root', '', 'elvis_store');
// Write the data to the database
$query = "INSERT INTO guitarwars VALUES (0, NOW(), '$name', '$score', '$screenshot')";
mysqli_query($dbc, $query);
// Confirm success with the user
echo '<p>Thanks for adding your new high score!</p>';
echo '<p><strong>Name:</strong> ' . $name . '<br />';
echo '<strong>Score:</strong> ' . $score ;
echo '<img src="'.GW_UPLOADPATH.$screenshot.'" alt="Score image" /></p>';
echo '<p><a href="index.php"><< Back to high scores</a></p>';
// Clear the score data to clear the form
$name = "";
$score = "";
mysqli_close($dbc);
}
else
{
echo '<p class="error">Verifique os campos: nome, pontuação e imagem.</p>';
}
}
?>
<hr />
<form enctype = "multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type = "hidden" name = "MAX_FILE_SIZE" value = "32768" />
<label for="name">Name:</label>
<input type="text" id="name" name="name" value="<?php if (!empty($name)) echo $name; ?>" /><br />
<label for="score">Pontuação:</label>
<input type="text" id="score" name="score" value="<?php if (!empty($score)) echo $score; ?>" /><br />
<label for = "screenshot">Captura de tela:</label>
<input type = "file" id = "screenshot" name = "screenshot" />
<hr />
<input type="submit" value="Add" name="submit" />
</form>
</body>
</html>
Qual o problema?
A variável screenshot, responsável pela captura das imagens retorna um valor nulo (isso pode ser percebido na linha echo $target;). Acredito que esse problema está afetando a chamada à função move_uploaded_file.
Há algo de errado com o uso da tag input type file?
Valeu!
Discussão (2)
Carregando comentários...