Pernahkah anda mengupload file seperti foto, mp3, video dll. Dan pernahkah anda mendownload seperti foto, mp3, video dll.
Disini kita akan bahas bagaimana cara proses upload dan download suatu file tersebut
Pertama kita buat database dengan nama upload&download :
-- Table structure for savefile
-- ----------------------------
CREATE TABLE `savefile` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`date` date NOT NULL,
`type` varchar(10) NOT NULL,
`size` int(11) NOT NULL,
`url` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=104 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records
-- ----------------------------
INSERT INTO `savefile` VALUES ('88', 'cantik', '2015-02-02', 'jpg', '8790', './data/cantik.jpg');
INSERT INTO `savefile` VALUES ('102', 'all night', '2015-02-07', 'mp3', '12009037', './data/all night.mp3');
INSERT INTO `savefile` VALUES ('103', 'cursor', '2015-02-07', 'rar', '14683525', './data/cursor.rar');
Kemudian buat file baru dengan nama config.php :
- <?php
- $host = "localhost";
- $user = "root";
- $pass = "root";
- $db_name = "upload&download";
- mysql_connect($host, $user, $pass) or die (mysql_error());
- mysql_select_db($db_name) or die (mysql_error());
- ?>
- <html>
- <head><title>Cara Membuat Form Upload dan Download</title></head>
- <link rel="stylesheet" type="text/css" href="style.css">
- <body>
- <div id="head"></div>
- <div id="header">
- <h2>Cara Membuat Form Upload dan Download</h2>
- Oleh Onehied
- <div id="menu">
- <a href="index.php" class="active">Home</a>
- <a href="upload.php">Upload</a>
- <a href="download.php">Download</a>
- </div>
- <div id="content">
- <p>Cara Membuat Form Upload dan Download oleh <a href="http://www.darionehied.blogspot.com/" target="_blank"><strong>darionehied</strong></a>
- Anda bisa mempublikasikan ulang, atau merubah Source Code ini.
- </p>
- </div>
- </div>
- </body>
- </html>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Cara Membuat Form Upload dan Download</title>
- <link rel="stylesheet" type="text/css" href="style.css">
- </head><body>
- <div id="head">
- <div id="header">
- <h2>Cara Membuat Form Upload dan Download</h2>
- <span>Oleh Onehied</span>
- <div id="menu">
- <a href="index.php">Home</a>
- <a href="upload.php" class="active">Upload</a>
- <a href="download.php">Download</a>
- </div>
- <p>Silakan Upload file yang anda inginkan.</p>
- <?php
- include 'config.php';
- if (isset($_POST['save'])){
- $file_name = $_POST['name'];
- $file_date = date("Y-m-d");
- $file_size = $_FILES['file']['size'];
- $file = $_FILES['file']['name'];
- $file_type = strtolower(end(explode('.', $file)));
- $file_tmp = $_FILES['file']['tmp_name'];
- $file_lokasi = './data/'.$file_name.'.'.$file_type;
- $file_tujuan = $file_lokasi;
- // Simpan ke Database
- $sql = "insert into savefile (name,date,type,size,url) values ('$file_name', '$file_date','$file_type','$file_size','$file_tujuan')";
- mysql_query($sql);
- // Simpan di Folder Gambar
- $lokasi = './data/'.$file_name.'.'.$file_type;
- move_uploaded_file($file_tmp,$lokasi);
- {echo"<script>alert('file Berhasil diupload !');</script>"; }
- }
- ?>
- <div id="content">
- <form method="post" enctype="multipart/form-data">
- <th align="left"><b>Name File : </b></th>
- <tr>
- <th align="left"><input type="text" name="name" size="35" maxlength="255" required />
- <br><br></th></tr>
- <tr>
- <th align="left"><b>Search File : </b></th></tr>
- <tr><th align="left"><input type="file" name="file" required /><br><br></th></tr>
- <tr>
- <th align="left"><input type="submit" value="Upload" name="save"></th></tr><br><br>
- </form>
- <div id="acc4"><a href="http://www.darionehied.blogspot.com/" target="_blank">darionehied</a></div>
- </div>
- </div>
- </div>
- </body>
- </html>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Cara Membuat Form Upload dan Download</title>
- <link rel="stylesheet" type="text/css" href="style.css">
- </head><body>
- <div id="container">
- <div id="header">
- <h2>Cara Membuat Form Upload dan Download</h2>
- <span>Oleh Onehied</span>
- <div id="menu">
- <a href="index.php">Home</a>
- <a href="upload.php">Upload</a>
- <a href="download.php" class="active">Download</a>
- </div>
- <div id="content">
- <p>Silahkan delete atau download file yang sudah di Upload. Untuk mendownload file ber-ekstensi (gambar) jpg, jpeg, bmp, png, gif dll Silakan klik kanan download with IDM, jika anda menggunakan IDM atau Anda bisa klik download kemudian klik kanan save image as.</p>
- <p align="right"><a href="http://www.darionehied.blogspot.com/" target="_blank"><strong>darionehied</strong></a></p>
- <p>
- <table width="100%">
- <tr>
- <td align="center" width="50"><b>Opsi</b></td>
- <td align="center"><b>No</b></td>
- <td align="center"><b>Name</b></td>
- <td align="center"><b>Date</b></td>
- <td align="center" width="70"><b>Type</b></td>
- <td align="center" width="70"><b>Size</b> (b)</td>
- </tr>
- <?php
- include 'config.php';
- $sql = "select * FROM savefile";
- $no = 1;
- $tampil = mysql_query($sql);
- while ($data = mysql_fetch_array($tampil)){
- ?>
- <tr>
- <td align="center"><?php echo $id ?><a href="delete.php?id=
- <?php echo $data['id']; ?>"><img src="images/delete.gif"></a>
- <a href="<?=$data['url'];?>"><img src="images/downloadb.png"></a></td>
- <td align="center"><?php echo $no; ?></td>
- <td align="center"><?php echo $data['name']; ?></td>
- <td align="center"><?php echo $type= date("Y-m-d"); ?></td>
- <td align="center"><?php echo $data['type']; ?></td>
- <td align="center"><?php echo $data['size']; ?></td>
- </tr>
- <?php
- $no++;
- }
- ?>
- </table>
- </p>
- </div>
- </div>
- </div>
- </body>
- </html>
- <?php
- include('config.php');
- $id = $_GET['id'];
- $query = mysql_query("delete from savefile where id='$id'") or die(mysql_error());
- if ($query) {
- header('location:download.php?message=delete');
- }
- ?>
- body {
- background-color:none;
- }
- #header {
- width:550px;
- margin:20px auto;
- padding:10px;
- text-align:center;
- background-color:#fff;
- box-shadow:0px 0px 3px #000;
- }
- h1, h2, h3 {
- margin:0;
- padding:0;
- }
- #menu {
- text-align:center;
- margin:15px 0px;
- border-top:1px solid #0099FF;
- border-bottom:1px solid #0099FF;
- }
- #menu a {
- display:inline-block;
- padding:5px 10px;
- text-decoration:none;
- color:#000;
- font-weight:bold;
- }
- #menu a:hover {
- background-color:#0099FF;
- }
- #menu a.active {
- background-color:#0099FF;
- }
- .table, td {
- border:1px solid #0099FF}
- #acc4 {
- text-align:right;
- }
- input[type=submit] {
- color:#ffff;
- width:80px;
- height: 25px;
- background:#3399FF;
- margin:10px 0px 0px 0px;
- border-radius:18px 18px 18px 18px;
- text-decoration:none;
- }
- a, a:link, a:visited { color:#0099FF; font-weight: normal; text-decoration: none;}
- #menu1 a:hover }
Download
Password
darionehied

Posting Komentar