Current time: 11-26-2024, 09:24 PM Hello There, Guest! (LoginRegister)


Post Reply 
Blop data type
Author Message
bodsink Offline
Newbie
*

Posts: 8
Joined: Apr 2009
Reputation: 0
Post: #5
RE: Blop data type
This mysql table

PHP Code:
CREATE TABLE `upload` (`idint(11NOT NULL 
auto_increment
,`namevarchar(30collate latin1_general_ci default 
NULL,`typevarchar(30collate latin1_general_ci default 
NULL, `sizeint(11) default NULL, `dateuploaddate default
NULL,`contentlongblob,`keterangantext collate latin1_general_ci,
PRIMARY KEY  (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci 

and this script php

PHP Code:
<?
    mysql_connect('localhost','userdb','passw');
    mysql_select_db('db_name');

    if($_POST['upload'])
    {
        $tanggal = date("Y-m-d");
         // membaca keterangan
        $ket = $_POST['ket'];
         
        // membaca nama file
        $fileName = $_FILES['userfile']['name'];     
         
        // membaca nama file temporary
        $tmpName  = $_FILES['userfile']['tmp_name']; 
         
        // membaca size file
        $fileSize = $_FILES['userfile']['size'];
         
        // membaca tipe file
        $fileType = $_FILES['userfile']['type'];
         
        // membaca isi file yang diupload 
        $fp  = fopen($tmpName, 'r');
        $content = fread($fp, filesize($tmpName));
        $content = addslashes($content);
        fclose($fp);
         
        // query SQL untuk menyimpan isi file dan informasi lainnya ke database
         
        $query = "INSERT INTO upload (name, size, type, content, dateupload, keterangan) 
                  VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$tanggal', '$ket')";
         
        $hasil = mysql_query($query);
         
        // konfirmasi proses upload
        if ($hasil)  echo "<p>File ".$fileName." telah terupload</p>";
        else echo "<p>File ".$fileName." gagal diupload</p>";

    }
    
    if($_GET['stat']=="download")
    {
        $id      = $_GET['id'];
 
        // query untuk membaca data file berdasarkan ID
        $query   = "SELECT * FROM upload WHERE id = $id";
         
        $hasil   = mysql_query($query);
        $data   = mysql_fetch_array($hasil);
         
        // mengenerate proses download file 
        header("Content-Disposition: attachment; filename=".$data['name']);
        header("Content-length: ".$data['size']);
        header("Content-type: ".$data['type']);
         
        echo $data['content'];

    }
?>
<h1>Upload File</h1>
<form method="post" enctype="multipart/form-data" action="./">
   Pilih File <br>
   <input name="userfile" type="file"><br>
   Keterangan:<br>
   <textarea name="keterangan"></textarea><br>
   <input name="upload" type="submit" value="Upload">
</form>

<?php
echo "<h2>Daftar File Upload</h2>"
 
// query untuk membaca semua file yang terupload
$query "SELECT * FROM upload";
$hasil mysql_query($query);
 
// menampilkan daftar file
echo "<table border='1'>";
echo 
"<tr><th>ID</th><th>Nama File</th><th>Tanggal Upload</th><th>Keterangan</th><th>Action</th></tr>";
while (
$data mysql_fetch_array($hasil))
{
    echo 
"<tr><td>".$data['id']."</td><td><a href='./?stat=download&id=".$data['id']."'>".$data['name']."</a></td><td>".$data['dateupload']."</td><td>".$data['ket']."</td></tr>";

echo 
"</table>";
 
?>

yes, we are conducting testing for users
sorry this script description language indonesia

Regards
Bodsink
12-22-2009 11:49 PM
Find all posts by this user Quote this message in a reply
Post Reply 


Messages In This Thread
Blop data type - bodsink - 12-22-2009, 09:19 PM
RE: Blop data type - TheCry - 12-22-2009, 09:34 PM
RE: Blop data type - bodsink - 12-22-2009, 10:42 PM
RE: Blop data type - TheCry - 12-22-2009, 11:10 PM
RE: Blop data type - bodsink - 12-22-2009 11:49 PM
RE: Blop data type - kilburn - 12-23-2009, 12:29 AM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)