當我提交表單時,圖像文件不會發送到他的目錄。其中的其他數據已成功插入。我看了幾個教程,並且我知道我不使用傳統方式,但我仍然期望它能夠工作,任何人都可以請看一下嗎?表單文件輸入(圖像)不會上傳到目標目標
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);
}
}
你得到了什麼錯誤?或者你的哪些測試失敗了? – Pitchinnate