lawang code

lawang Code


Tanyakan kode disini

tidak dapat tersimpan di database

ditanyakan oleh Muh. Rezky Anugerah. A 2 tahun yang lalu

Gambar dapat tersimpan ke file direktori, tapi penyimpanan data gambar tidak.

<?php
    $target_dir = "C:/xampp/htdocs/latihan_upload/uploads/";
    $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
    $uploadOk = 1;
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
    $fileName = $_FILES["fileToUpload"]["name"];
    include "koneksi.php";

    if(isset($_POST["submit"])) {
        $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
        if($check !== false) {
            echo "File is an image - " . $check["mime"] . ".";
            $uploadOk = 1;
        } else {
            echo "File is not an image.";
            $uploadOk = 0;
        }
    }
    if (file_exists($target_file)) {
        echo "Sorry, file already exists.";
        $uploadOk = 0;
    }

    if ($_FILES["fileToUpload"]["size"] > 2000000) {
        echo "Sorry, your file is too large.";
        $uploadOk = 0;
    }

    if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
    && $imageFileType != "gif" ) {
        echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
        $uploadOk = 0;
    }

      $carikode = mysql_query("select max(id) from foto") or die (mysql_error());
      $datakode = mysql_fetch_array($carikode);
      $jumlah_data = mysql_num_rows($carikode);
      if ($datakode) {
       $nilaikode = substr($jumlah_data[0], 1);
       $kode = (int) $nilaikode;
       $kode = $jumlah_data + 1;
       $hasilkode = "IMG".str_pad($kode, 3, "0", STR_PAD_LEFT);
      } else {
       $hasilkode = "IMG001";
      }
    $sql = "INSERT INTO foto ('id','gambar','keterangan') values ('$hasilkode','$fileName','".$_POST['kete']."')";
    mysql_query($sql) or die (mysql_error());
    if ($uploadOk == 0) {
        echo "Sorry, your file was not uploaded.";
    } else {
        if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
            echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
        } else {
            echo "Sorry, there was an error uploading your file.";
        }
    }
    ?>

Anda harus login terlebih dahulu untuk memberikan komentar

Recent Tag

X 6
X 48
X 14
X 10
X 1
X 5
X 4
X 18
X 10

Bantuan

Help

Feedback

Help