当我提交表单时,图像文件不会发送到他的目录。其中的其余数据已成功插入。我看了几个教程,我知道我没有使用最节省的方法,但我仍然希望它能够工作,有人可以看看吗?
function addData($name, $price, $description, $files)
{
if(!empty($name) || !empty($price) || !empty($description))
{
if($sql = $this->db->prepare("SELECT * FROM products WHERE name= ? LIMIT 1"))
{
$sql->bind_param('s', $name);
$sql->execute();
$sql->store_result();
$sql->fetch();
$numrows = $sql->num_rows;
print_r($numrows);
}
else
{
echo "something is wrong";
}
if($numrows>0)
{
echo 'duplicate, go to <a href="index.php?res=resources&adm=admin&page=inventory.php">same page</a>';
}
else
{
if($insert = $this->db->prepare("INSERT INTO products (name, price, description) VALUES(?, ?, ?)"))
{
$insert->bind_param('sds', $name, $price, $description);
$insert->execute();
}
else
{
echo "failed to prepare";
}
//The uploaden image is sent to temp map
if(is_uploaded_file($files['image']['tmp_name']))
{
$valid_types = array(
"image/gif",
"image/png",
"image/jpeg",
"image/pjpeg",
);
if (in_array($files["file"]["type"], $valid_types))
{
$uploaddir = "./webshop/public/img/content/";
if(move_uploaded_file($files['image']['tmp_name'], $uploaddir."/".$files['image']['name']));
}
//Shows where its stored
echo "Stored in: " . 'C:/xampp/htdocs/webshop/public/img/content/' . $files["file"]["name"];
}
else
{
echo "didnt inserted the damn thing!";
}
}
print_r($files);
}
}