很抱歉,我无法弄清楚我的代码中的错误在哪里,它必须是一个简单的{
这是一个将imgs上传到数据库的简单表单,所以如果有人想让它随意使用它。
<html>
<body>
<form method="post" action="">
<p>Selecionar imagem:</p>
<input type="file" name="fileToUpload" id="fileToUpload">
<p>descricao:</p>
<input name="descricao" type="text">
<p>categoria:</p>
<input name="categoria" type="text">
<input type="submit" value="Submit" name="submit">
</form>
</body>
</html>
<?php
$con = mysql_connect("localhost", "root", "", "galeria");
if (!$con)
{
die('Could not connect: '.mysql_error());
}
mysql_select_db("galeria", $con);
if (isset($_POST["submit"]))
{
$sql = "INSERT INTO gallery (id,lowsrc,fullsrc,description,category)
VALUES
('','$_POST[fileToUpload]','$_POST[fileToUpload]','$_POST[descricao]','$_POST[categoria]')";
if (!mysql_query($sql, $con))
{
die('ERRO: '.mysql_error());
}
echo "adicionado";
if (array_key_exists("submit", $_POST))
{
$target_dir = "full/";
$target_file = $target_dir.basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
if (isset($_POST["submit"]))
{
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if ($check !== false)
{
echo "OK - ".$check["mime"].".";
$uploadOk = 1;
}
else
{
echo "Não é uma imagem";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file))
{
echo "Ficheiro ja existe!";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000)
{
echo "Ficheiro muito grande!";
$uploadOk = 0;
}
// Allow certain file formats
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif")
{
echo "Apenas JPG, JPEG, PNG e GIF são permitidos";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0)
{
echo "ERRO";
// if everything is ok, try to upload file
}
else
{
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))
{
echo "Upload Feito";
}
else
{
echo "ERRO";
}
}
}
?>
答案 0 :(得分:0)
我已经解析了你的代码,它说你需要在最后一个结束标记之前添加一个额外的括号}
。
答案 1 :(得分:0)
在末尾添加结束花括号}