if/elseif ステートメントで画像をアップロードしようとしています。$_FILES を関数パラメーターとして渡しました。print_r は array() を出力するため、渡すことはうまくいったと思います。それとも、私が作成したロジックに何か問題がありますか? 誰か特定してくれませんか?前もって感謝します!
<?php
require_once('../resources/library/admin.class.php');
$obj_admin = new admin();
echo $obj_admin->product_list;
echo '<h1>inventory list</h1></br>';
$obj_admin->displayList();
$obj_admin->editData();
$obj_admin->deleteData();
$add[] = '<form name="invent" method="post" action="index.php?res=resources&adm=admin&page=inventory.php" class="ínvent">';
$add[] = '<fieldset>';
$add[] = '<legend>Add products</legend>';
$add[] = "<label for='name'>name</label>";
$add[] = "<input type='text' name='user' value='Grachten' />";
$add[] = '</br>';
$add[] = "<label for='price'>price</label>";
$add[] = "<input type='number' name='price' value='150' />";
$add[] = '</br>';
$add[] = "<label for='description'>description</label>";
$add[] = "<textarea name='description' rows='10' cols= '80'>Its the best!</textarea>";
$add[] = '</br>';
$add[] = "<label for='img'>img</label>";
$add[] = "<input name='image' accept='image/jpeg' type='file' value='files'>";
$add[] = '</br>';
$add[] ="<input type='submit' name='submit'/>";
$add[] = '</fieldset>';
$add[] = '</form>';
echo implode($add);
if(isset($_POST['submit']))
{
$name = $_POST['user'];
$price = $_POST['price'];
$description = $_POST['description'];
$obj_admin->addData($name, $price, $description, $_FILES);
}
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();
}
//The uploaden image is sent to temp map
elseif(isset($files['image']['size'])<=2048000)
{
if ($files["image"]["error"] > 0)
{
echo "Return Code: " . $files["image"]["error"] . "<br />";
}
else
{
$uploaddir = "C:/xampp/htdocs/webshop/public/img/content";
$moved = move_uploaded_file($files['image']['tmp_name'], $uploaddir/$files['image']);
if($moved)
{
echo "succes";
}
else
{
echo "failure";
}
}
//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);
}