[英]Upload multiple image in database PHP
我在网上找到下面的代码以在数据库中导入多个图像,但是以下情况似乎总是返回false,因为从不执行内部代码: (move_uploaded_file($tmpFilePath, $filePath))
。 是因为path
吗? 我没有做任何更改,并且我假设上uploaded
是自动创建的。
<?php include 'connection.php';?>
<?php
if(isset($_POST['search'])){
if(count($_FILES['upload']['name']) > 0){
echo "OhhYESHOOO";
//Loop through each file
for($i=0; $i<count($_FILES['upload']['name']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
echo "HERE";
//Make sure we have a filepath
if($tmpFilePath != ""){
echo "Entered";
//save the filename
$shortname = $_FILES['upload']['name'][$i];
//echo "*$shortname";
//save the url and the file
$filePath = "uploaded/" . date('d-m-Y-H-i-s').'-'.$_FILES['upload']['name'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $filePath)) {
echo "Entered Again";
$files[] = $shortname;
//insert into db
//use $shortname for the filename
//use $filePath for the relative url to the file
}
}
}
}
//show success message
echo "<h1>Uploaded:</h1>";
if(is_array($files)){
echo "<ul>";
foreach($files as $file){
echo "<li>$file</li>";
}
echo "</ul>";
}
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.