gpt4 book ai didi

php - 使用PHP上传图片失败

转载 作者:行者123 更新时间:2023-11-30 00:02:10 24 4
gpt4 key购买 nike

我尝试使用以下代码上传图像,但失败并出现错误(如下)。谁能告诉我为什么?

<?php
include("mysqlconnect.php");

function GetImageExtension($imagetype)
{
if(empty($imagetype)) return false;
switch($imagetype)
{
case 'image/bmp': return '.bmp';
case 'image/gif': return '.gif';
case 'image/jpeg': return '.jpg';
case 'image/png': return '.png';
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 'images_tbl' ('images_path','submission_date') VALUES ('".$target_path."','".date("Y-m-d")."')";

mysql_query($query_upload) or die("error in $query_upload == ----> ".mysql_error());
} else {
exit("Error While uploading image on the server");
}
}
?>

最佳答案

你的插入语句必须像这样开始

INSERT into `images_tbl`

不是

INSERT into 'images_tbl'

您必须将表名和列名用反引号 (`) 括起来,而不是用单引号括起来,因为用单引号括起来不是有效的语法。更多内容可以查看manual of mysql其中包含描述和语法

关于php - 使用PHP上传图片失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24933068/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com