在一列中插入多个图像作为逗号分隔列表

时间:2018-04-26 16:54:25

标签: php mysql web-applications

我正在创建一个房地产Web应用程序,现在正在创建一个表单,我将允许编辑器输入有关某个属性的数据,其中这些输入是图像,但我不知道如何在一列中输入多个值在数据库中。  这是我的代码。

if(!empty($_FILES)){
    $photo1 = $_FILES['photo1'];
    $photo2 = $_FILES['photo2'];
    $photo3 = $_FILES['photo3'];
    $photo4 = $_FILES['photo4'];
    $photo5 = $_FILES['photo5'];
    $photo6 = $_FILES['photo6'];
    $photo7 = $_FILES['photo7'];
    $photo = [$photo1,$photo2,$photo3,$photo4,$photo5,$photo6,$photo7];
    foreach ($photo as $photos) {
        $name = $photos['name'];
        $nameArray = explode('.',$name);
        $filename = $nameArray[0];
        $fileEXT = $nameArray[1];
        $mime = explode('/', $photos['type']);
        $mimeType = $mime[0];
        $mimeEXT = $mime[1];
        $temploc = $photos['tmp_name'];
        $filesize = $photos['size'];
        $allowed = array('png','jpg','jpeg','gif',);
        $uploadname = md5(microtime()).'.'.$fileEXT;
        $uploadpath = LINKURL.'/imgs/photos/'.$uploadname;
        $dbpath = '/realeastate/imgs/photos/'.$uploadname;
        if($mimeType != 'image'){
            $errors[]= 'File must be an image';
        }
        if(!in_array(strtolower($fileEXT), $allowed)){
            $errors[]= 'The photo extension must be jpg,png,jpeg or gif.';
        }
        if($filesize > 25000000){
           $errors[]= 'The file size must be less than 25MB.';
        }
        if(strtolower($fileEXT) != $mimeEXT && $mimeEXT == 'jpeg' && strtolower($fileEXT) != 'jpg' ){
            $errors[]= 'File extension does not match the file.';
        }

        if(!empty($errors)){
            echo show_errors($errors);
      } else {
            //upload file and insert into database
            if (!empty($_FILES)) {
                move_uploaded_file($temploc,$uploadpath);
            }
            if(isset($_GET['edit'])){
                $db->query("UPDATE property SET taken ='$taken' WHERE id ='$edit_id'");
            }else{ 
                $db->query("INSERT INTO property (category,status,purpose,cover,images,city,place,price,payment,garage,wideness,visit,takenhome,hospital,school,market,bank,church,mosque,government,datetostart,floor) VALUES ('$category','$status','$purpose','$dbpath','$city','$place','$price','$payment','$garage','$wide','$dprice','$adprice','$hospital','$school','$church','$mosque','$government','$opendate','$floor')");
            }

        }

    }

    $_SESSION['success'] = 'Property  Added successful';
    header('Location: house.php');

 }

0 个答案:

没有答案