嘿,我一直在网站上工作,我想上传图片。我在MySQL中有以下表格:
<?php
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
<!DOCTYPE HTML>
<html>
<body>
<form method="post" enctype="multipart/form-data">
<input type="file" name="image">
<input type="submit" name="submit" value="submit">
</form>
<?php
if(isset($_POST['submit']))
{
if(getimagesize($_FILES['image']['tmp_name'])== FALSE)
{
echo "Please select and image";
}
else {
$image = addslashes($_FILES['image']['tmp_name']);
$name = addslashes($_FILES['image']['tmp_name']);
$image = file_get_contents($_FILES['image']['tmp_name']);
$image = base64_encode($image);
saveimage($name,$image);
}
}
function saveimage($name , $image)
{
$query = "insert into image (name,image)
values ('$name', '$image')";
$result = mysqli_query($query,$conn);
if($result)
{
echo "<p>Image Uploaded</p>";
}
else {
echo "<p>Image not Uploaded</p> " . mysql_error();
}
}
?>
</body>
</html>
当我尝试上传图片时,我得到以下内容:
E_NOTICE:类型8 - 未定义变量:_FILES - 在第28行 E_WARNING:类型2 - getimagesize():文件名不能为空 - 在第28行 请选择并成像
我不确定我做错了什么,而且在php.ini中我设置了post_max_size = 20M
有什么想法吗?