Mengupload file mp3 dengan satu file PHP

Pertama-tama buat struktur direktori file seperti berikut ini

lalu buka file index.php dan tulis code seperti dibawah ini

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Mengupload file mp3 dengan satu file PHP</title>
</head>
<body>
<h2>Mengupload file mp3 dengan satu file PHP</h2>
<form name="form_upload" method="POST" enctype="multipart/form-data" action="index.php?act=upload">
<table>
<tr>
<td>Upload file mp3</td><td></td>
<td>
<input type="file" name="mp3" value="" />
</td>
</tr>
<tr>
<td></td>
<td></td>
<td>
<input type="submit" value="Upload" name="upload" />
</td>
</tr>
</table>
</form>
<?php
$act = $_REQUEST[act];
if ($act == upload) {
$filename = $_FILES[mp3][tmp_name];
$destination = "mp3/" . $_FILES[mp3][name];
if (empty($filename)) {
echo"Upload mp3 dulu dong...!";
} else {
if (move_uploaded_file($filename, $destination)) {
echo "mp3 berjudul  = " . $_FILES[mp3][name] . " berhasil diupload";
} else {
echo"mp3 gagal diupload";
}
}
}
?>
</body>
</html>
Selanjutnya jalankan file index.php di localhost. Jika file mp3 berhasil diupload ke folder mp3 maka program anda berhasil

Selamat mencoba...:-)

0 comments:

Posting Komentar