如何不将图像/存储到数据库中(多个上传手册)

时间:2016-08-19 10:02:08

标签: php image upload image-uploading

我有一些问题,当我想将图像存储到数据库中时,但是当我不想存储它时,但是php保存商店文件夹地址(图像/) 这是我的代码

$file_name  = $_FILES['gambar1']['name'];
            $file_size  = $_FILES['gambar1']['size'];
            $file_tmp   = $_FILES['gambar1']['tmp_name'];
            $file_name2 = $_FILES['gambar2']['name'];
            $file_size2 = $_FILES['gambar2']['size'];
            $file_tmp2  = $_FILES['gambar2']['tmp_name'];
            $file_name3 = $_FILES['gambar3']['name'];
            $file_size3 = $_FILES['gambar3']['size'];
            $file_tmp3  = $_FILES['gambar3']['tmp_name'];
            $file_name4 = $_FILES['gambar4']['name'];
            $file_size4 = $_FILES['gambar4']['size'];
            $file_tmp4  = $_FILES['gambar4']['tmp_name'];
            $tmp = explode('.', $file_name);
            $file_ext   = end($tmp);
            $ext_boleh  = array("jpg", "jpeg", "png", "bmp", "gif");
            if($file_name!="" or $file_name2!="" or $file_name3!="" or $file_name4!=""){
                if(in_array($file_ext, $ext_boleh))
                {
                    if($file_size <= 2*1024*1024)   
                    {
                        $sumber     = $file_tmp;
                        $tujuan     = "images/". $file_name;

                        $sumber2    = $file_tmp2;
                        $tujuan2    = "images/". $file_name2;

                        $sumber3    = $file_tmp3;
                        $tujuan3    = "images/". $file_name3;

                        $sumber4    = $file_tmp4;
                        $tujuan4    = "images/". $file_name4;

                        move_uploaded_file($sumber, $tujuan);
                        move_uploaded_file($sumber2, $tujuan2);
                        move_uploaded_file($sumber3, $tujuan3);
                        move_uploaded_file($sumber4, $tujuan4);
                        $sql="insert into db_latihan(kode_latihan,kode_tipe,jenis,otot_utama,otot_lainnya,nama,alat,deskripsi,gambar1,gambar2,gambar3,gambar4)values('$_POST[kode]','$_POST[kdtipe]','$_POST[Jenis]','$_POST[ototutama]','$_POST[ototlain]','$_POST[nama]','$_POST[alat]','$_POST[deskripsi]','$tujuan','$tujuan2','$tujuan3','$tujuan4')";
                        mysqli_query($koneksi,$sql);

我知道问题出现在这里:

  if($file_name!="" or $file_name2!="" or $file_name3!="" or $file_name4!="")

所以任何人都有最简单的方法,如果我只存储在1 gambar ex(gambar1)但不存储gambar 2,3和4的地址?

0 个答案:

没有答案