ada yang tau mksd eror ini apa??

 Warning: getimagesize(): Filename cannot be empty in C:\xampp\htdocs\BBM\controlers\kendaraan\Simpan-data-kendaraan.php on line 18
File is not an image.Sorry, only JPG, JPEG, PNG & GIF files are allowed.Sorry, your file was not uploaded.

ini source codenya

 <?php
include "/../../class/kendaraan.php";
$kendaraan = new kendaraan();

    //Untuk Instansiasi Dari Table Keberangkatab
$kendaraan->merek       =$_POST['merek'];
$kendaraan->pemegang    =$_POST['pemegang'];
$kendaraan->plat_nomer  =$_POST['plat_nomer'];
$kendaraan->type        =$_POST['type'];
$namafile               =$_FILES['gambar']['name'];
$kendaraan->gambar      =$namafile;
$target_dir = "../../assets/images/car/";
$target_file = $target_dir . basename($namafile);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
    // Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["gambar"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
    // Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}

    // Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
    && $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
    // Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
    // if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["gambar"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["gambar"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}

$error = $kendaraan->add_kendaraan();

if(!$error){
        echo "$error";

       }else{
        echo "$error";
    }
    ?>

avatar samsularifin05
@samsularifin05

114 Kontribusi 13 Poin

Diperbarui 5 tahun yang lalu

1 Jawaban:

<pre> Warning: getimagesize(): Filename cannot be empty </pre>

Warning ini aja harusnya udah mnjelaskan apa yang salah sama kode agan. Itu artinya parameter filename yang dibutuhin sama getimagesize() gak boleh kosong, dan di coding agan itu kosong. Coba check dulu pada bagian $_FILES itu apa ada isinya atau tidak.

Dengan filename yang kosong tadi maka getimagesize() memiliki nilai return berupa FALSE. Langsung ke lempar lagi ke ELSE nya yang

<pre> echo "File is not an image."; </pre>

Setelah itu, karena variabel $namafile juga == $_FILES yang ada pada parameter di getimagesize() maka akan menjadi error pada saat pengecekan ekstensi pada filenya. Sekali lagi, itu terjadi karena $namafile / $_FILES['gambar']['name'] / $_FILES['gambar']['tmp_name'] ini tidak ada isinya.

avatar markeronly
@markeronly

378 Kontribusi 230 Poin

Dipost 5 tahun yang lalu

Login untuk ikut Jawaban