我有问题让PHP插入图像路径或目录到MySQL数据库。它只是存储图像名称,而不是图像的路径和名称。此外,我正在重命名图像以匹配存储在其下的项目标题(例如蓝色车标题,蓝色车图像名称)。而不是上传新的图像名称,它只存储原始图像名称。插入图像目录到MySQL
这是我的重命名并上传图像等:
// The directory that will recieve the uploaded file
$dir = 'uploads/';
//variables for images
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["picture"]["name"]);
$extension = end($temp);
if(isset($_POST['submit'])) {
if (strlen($title)>0 && strlen($description)>0) {
move_uploaded_file($_FILES['picture']['tmp_name'], $dir . "/" . $title ."." . $extension);
// Query database and insert data into item table
$itemQry = 'INSERT INTO items (title, picture, startPrice, category, description, quantity, location, sellingFormat, duration, paymentType, postageDetails)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
$statement = $conn->prepare($itemQry);
$statement->bind_param('sssssssssss', $title, $_FILES['picture']['name'], $startPrice, $category, $description, $quantity, $location, $sellingFormat, $duration, $paymentType, $postageDetails);
$statement->execute();
*它只存储图像名称*因为这是你告诉它做的 –
$ _FILES ['picture'] ['name']将只返回图像的名称(例如file.jpg) – Akintunde007
如何我要改变这个吗? – Joel