assalamu'alaikum wr wb
Buat lah file index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Upload banyak file dengan php</title>
<style type="text/css">
#form-upload {
width:500px;
margin:0 auto;
border:1px solid #ccc;
border-radius:10px;
padding:10px;
background-color:#E2FEEA;
font:14px "Trebuchet MS";
}
</style>
</head>
<body>
<div id="form-upload">
<form action="coba.php" method="post" enctype="multipart/form-data">
<h3 align="center">Isikan judul dan pilih file yang akan di upload :</h3>
<p> File 1<br />Judul : <input name="judul[]" type="text" size="30" maxlength="30" /> <input name="nama_file[]" type="file" /></p>
<p>File 2<br />Judul : <input name="judul[]" type="text" size="30" maxlength="30" /> <input name="nama_file[]" type="file" /></p>
<p>File 3<br /> Judul : <input name="judul[]" type="text" size="30" maxlength="30" /> <input name="nama_file[]" type="file" /></p>
<p>* Hanya file gambar jpg/gif/png</p>
<p align="center"><input name="btnKirim" type="submit" id="btnKirim" value="Kirim File" /></p>
</form>
</div>
</body>
</html>
setelah selesai dibuat, langkah selanjutnya buat nama file coba.php
<?php
$namafolder="photo/"; //tempat menyimpan file
for($i=0; $i<=count($_FILES['nama_file']); $i++)
{
if (!empty($_FILES["nama_file"]["tmp_name"][$i]))
{
$jenis_gambar=$_FILES['nama_file']['type'][$i];
$judul_gambar=$_POST['judul'][$i];
if($jenis_gambar=="image/jpeg" || $jenis_gambar=="image/jpg" || $jenis_gambar=="image/gif" || $jenis_gambar=="image/x-png")
{
$gambar = $namafolder . basename($_FILES['nama_file']['name'][$i]);
if (move_uploaded_file($_FILES['nama_file']['tmp_name'][$i], $gambar)) {
//tampilkan ke layar
echo "Judul Gambar : ".$judul_gambar."<br />";
echo "Jenis Gambar : ".$jenis_gambar."<br />";
echo "<img src=\"$gambar\" width=\"100\" alt=\"$judul_gambar\" /><br />";
//tambahkan proses menyimpan database jika diperlukan seperti berikut
//mysql_query("insert into tb_mgambar(judul_gambar,nama_file) values('$judul_gambar','$gambar')") or die(mysql_error());
}
}
else
{
echo "Jenis gambar yang anda kirim salah. Harus .jpg .gif .png<br />";
}
}
}
?>
Selamat Mencoba euy
Submer : http://www.zainalhakim.web.id/download/contoh-upload-banyak-file-dengan-php.html
Langganan:
Posting Komentar (Atom)
In the beach
25 April 2011 Slideshow: Lakek’s trip from Jakarta, Jawa, Indonesia to Sukabumi was created by TripAdvisor. See another Sukabumi slideshow. Create a free slideshow with music from your travel photos.
0 komentar:
Posting Komentar