bagaimana caranya agar form uploadnya muncul ?

Oleh dandyrafli 1 0 pada Jumat, 14 Agu 2020, 12:17:14


Kembali ke forum umum


Petunjuk Diskusi
Silahkan masuk untuk berdiskusi



saya mempunya kode php seperti ini

<?php
$imageinfo = getimagesize($_FILES['img']['tmp_name']);
if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg') {
echo "<center><br>Sorry, we only accept GIF and JPEG images</br><br>param name: img<br>u can upload with CSRF";
exit;
}
$uploaddir = 'ex/';
$uploadfile = $uploaddir . basename($_FILES['img']['name']);
if (move_uploaded_file($_FILES['img']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "File uploading failed.\n";
}?>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" size="20" name="img" />
<input type="submit" name="upload" value="Upload" />
</form>

tetapi form upload tidak muncul, response nya adalah menampilkan data dari
echo "<center><br>Sorry, we only accept GIF and JPEG images</br><br>param name: img<br>u can upload with CSRF";
0 jempol


bramanto
300
1157
· 4 tahun, 3 bulan yang lalu · 0 jempol

Halo coder @dandyrafli, sesuai dengan sintaks yang dituliskan, form tidak akan muncul dikarenakan kondisi (pada ifnya) memang benar.

Jadi kamu bisa menuliskan seperti ini.

<?php
if(@$_POST['upload']){
    $imageinfo = getimagesize($_FILES['img']['tmp_name']);
    if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg') {
        echo "<center><br>Sorry, we only accept GIF and JPEG images</br><br>param name: img<br>u can upload with CSRF";
        exit;
    }
    $uploaddir = 'ex/';
    $uploadfile = $uploaddir . basename($_FILES['img']['name']);
    if (move_uploaded_file($_FILES['img']['tmp_name'], $uploadfile)) {
        echo "File is valid, and was successfully uploaded.\n";
    } else {
        echo "File uploading failed.\n";
    }
}

?>
<form action="" method="post" enctype="multipart/form-data">
    <input type="file" size="20" name="img" />
    <input type="submit" name="upload" value="Upload" />
</form>

Silahkan dipahami lagi yaah.. Semangat belajarnya!