我已经有一个代码 - 请在下面检查。这段代码工作正常,但我只是意识到它只会将文件添加到上传文件夹中,并且不会向数据库添加任何内容。有人能帮我填补空白吗?我想使用一个数组并尽可能简单。使用数组将多个图像名称插入数据库
请向下滚动到执行代码并将图像放入文件夹的注释。
uploader.php
<?php
if (isset($_POST['submit'])) {
$j = 0; // Variable for indexing uploaded image.
$target_path = "uploads/test/"; // Declaring Path for uploaded images.
for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
// Loop to get individual element from the array
$validextensions = array("jpeg", "jpg", "png");
// Extensions which are allowed.
$ext = explode('.', basename($_FILES['file']['name'][$i]));
// Explode file name from dot(.)
$file_extension = end($ext);
// Store extensions in the variable.
$target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext) - 1];
// Set the target path with a new name of image.
$j = $j + 1;
// Increment the number of uploaded images according to the files in array.
if (($_FILES["file"]["size"][$i] < 100000)
// Approx. 100kb files can be uploaded.
&& in_array($file_extension, $validextensions)) {
if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {
// If file moved to uploads folder.
?>
<div id="noerror">Image <?php echo $j;?>-->Image Uploaded!</div>
<?php
// File was moved, so execute code here
// In this code I would like to add file name to a DB
} else { // If File Was Not Moved.
?>
<div id="error">Image <?php echo $j;?>--> <b>Please Try Again!</b></div>
<?php
}
} else { // If File Size And File Type Was Incorrect.
?>
<div id="error">Image <?php echo $j;?>--> <b>Check file Size or Type</b></div>
<?php
}
}
}
?>
您的查询行似乎不工作。我用myPHP测试过它,它给我语法错误。 – CharlotteOswald 2015-04-05 10:05:49
你能解释我的错误吗?你添加了数据库连接文件吗? – 2015-04-05 11:53:00