图像数据无法保存在数据库中

时间:2017-03-27 04:16:59

标签: php mysql

图像数据无法保存在数据库中。我该怎么做才能解决这个问题?

<?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;
    }

  $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']."') or die (mysql_error())";
mysql_query($sql);
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.";
    }
}
?>

0 个答案:

没有答案