在上传多张图片时遇到问题?附加的db图像

网络资源
<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代码:

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());
}

这里显示上传的文件夹名和图片名,我只需要用逗号分隔图片名,请看图片

注意:
在数据库中,路径上载目录文件夹和图像图像将进入数据库,我只希望图像名称用逗号分隔。例如,预期的输出是Chrysanthemum.jpg,Desert.jpg。我不知道是什么问题。请指导我。请看一下我的代码和图片附件的详细信息。

理查德·豪瑟姆(Richard Housham)

这样做会很容易-缩进代码可以帮助人们阅读和帮助您。

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());
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章