Toko baju super murah

www.bajusupermurah.com menjual pakaian berkwalitas dan termurah

Belajar PHP ( Upload file dengan PHP )


pertama buat index.html dulu, yang isinya:

^^^^^index.html^^^^^

<form action=”upload_file.php” method=”post” enctype=”multipart/form-data”>
<label for=”file”>Filename:</label>
<input type=”file” name=”file” id=”file”>
<input type=”submit” name=”submit” id=”submit”>
</form>

kemudian buat upload_file.php, yang isinya:

^^^^^upload_file.php^^^^^^
<?php

if($FILES[“file”][“error”]>0){
echo “error : ” . $_FILES[“file”][“error”].”<br>”;
}
else {
echo ” upload: ” . $_FILES[“file”][“name”]. “<br>”;
echo “type: ” . $_FILES[“file”][“type”]. “<br>”;
echo “size: ” . ($_FILES[“file”][“size”] / 1024). “Kb<br>”; // jk mau dalam Kb
echo “stored in: ” . $_FILES[“file”][“tmp_name”]. “<br>”;
}
?>

validasi saat upload

cth: validasi upload file gambar dengan maks size = 20 kb

ganti upload_file.php tadi dengan:

<?php
if((($_FILES[“file”][“type”] == “image/gif”) || ($_FILES[“file”][“type”] == “image/jpeg”) || ($_FILES[“file”][“type”] == “image/pjpeg”) && ($_FILES[“file”][“size”] < 20000))
{
if($_FILES[“file”][“error”] > 0)
{
echo “error: ” . $_FILES[“file”][“error”]. “<br>”;
}
else
{
echo ” upload: ” . $_FILES[“file”][“name”]. “<br>”;
echo “type: ” . $_FILES[“file”][“type”]. “<br>”;
echo “size: ” . ($_FILES[“file”][“size”] / 1024). “Kb<br>”;
echo “stored in: ” . $_FILES[“file”][“tmp_name”]. “<br>”;
}
}
else
{
echo “invalid file”;
}
?>

5 April 2009 - Posted by | Tutorial PHP | , , , , , ,

Belum ada komentar.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google

You are commenting using your Google account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s

%d blogger menyukai ini: