我正在尝试将图像上传到名为tbl_images的数据库表中,并将图像文件夹保存在与源文件相同的文件夹中!我收到错误“解析错误:语法错误,意外'$ imagename'(T_VARIABLE)”
这是我的index.php代码
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<form action="saveimage.php" method="post" enctype="multipart/form-data">
<h2>Please click on Upload button</h2>
<input type="file" name="uploadedimage">
<input type="submit" name="Upload Image" value="Upload Image">
</form>
</body>
</html>
这是saveimage.php文件。不知道这里有什么问题。任何帮助表示赞赏。
<?php
include ("connection.php");
function GetImageExtension($imagetype)
{
if(empty($imagetype)) return false;
switch($imagetype)
{
case 'image/bmp':return '.bmp';
case 'image/gif':return '.gif';
case 'image/png':return '.png';
case 'image/jpeg':return '.jpeg';
default: return false;
}
}
if(!empty($_FILES["uploadedimage"]["name"]))
{
$file_name=$_FILES["uploadedimage"]["name"];
$temp_name=$_FILES["uploadedimage"]["tmp_name"];
$imgtype=$_FILES["uploadedimage"]["type"];
$ext=GetImageExtension($imgtype)
$imagename=date("d-m-Y")."-".time().$.$ext;
$target_path="images/".$imagename;
if(move_uploaded_file($temp_name, $target_path))
{
$query_upload="INSERT into tbl_images
(image_name,submission_date)
values
('".$imagename."','".date("Y-m-d")."')";
mysqli_query($con,$query_upload);
echo "Image has been uploaded";
}
}
else {
echo "Can not upload image";
}
?>