2016-09-21 63 views
0
<form name="property" action="" method="post" enctype="multipart/form-data"> 
Select Image 
<input type="file" name="upload[]" multiple="multiple" id="image"/> 
<input type="submit" value="Submit" name="submit" style="width:200px; height:30px;" /> 
</form> 

我的PHP代码:有多个图片上传的问题? DB图像连接

if(isset($_POST['submit'])) 
{ 
$total = count($_FILES['upload']['name']); 
for($i=0; $i<$total; $i++) 
{ 
$tmpFilePath = $_FILES['upload']['tmp_name'][$i]; 
if ($tmpFilePath != "") 
{ 
$newFilePath[] = "upload/" . $_FILES['upload']['name'][$i]; 
$values_insert = implode(',', $newFilePath); 
if(move_uploaded_file($tmpFilePath, $newFilePath)) 
{ 
$date=date("Y-m-d"); 
} 
} 
} 
$d=mysql_query("INSERT INTO properties (iname,cdate) VALUES('".$values_insert."',NOW())") or die(mysql_error()); 
} 

Here It shows the upload foldername and image name, I want only image name sperated by comma, please see the image

注:
在数据库的路径上传目录文件夹和图像的图像将会数据库,我想只图像名称分隔逗号。例如预期的输出是Chrysanthemum.jpg,Desert.jpg。我不知道是什么问题。请引导me.kindly看看我的代码和图像附件的详细信息。

回答

0

这会做fyi缩进代码将帮助人们阅读和帮助你。

if(isset($_POST['submit'])) 
    { 
    $total = count($_FILES['upload']['name']); 
    for($i=0; $i<$total; $i++) 
    { 
    $tmpFilePath = $_FILES['upload']['tmp_name'][$i]; 
    if ($tmpFilePath != "") 
    { 
    $newFilePath = "upload/" . $_FILES['upload']['name'][$i]; 
    $newFilePath2[] = $_FILES['upload']['name'][$i]; 
    $values_insert = implode(',', $newFilePath2); 
    if(move_uploaded_file($tmpFilePath, $newFilePath)) 
    { 
    $date=date("Y-m-d"); 
    } 
    } 
    } 
    $d=mysql_query("INSERT INTO properties (iname,cdate) VALUES('".$values_insert."',NOW())") or die(mysql_error()); 
    }