upload file on database through php code
- by ruhit
hi all I have made an application to upload files and its workingout well.now I want to upload my files on database and I also want to display the uploaded files names on my listby accessing the database....so kindly help me. my codes are given below-
function uploadFile() {
    global $template;
    //$this->UM_index = $this->session->getUserId();
    switch($_REQUEST['cmd']){
        case 'upload':
            $filename = array();
             //set upload directory
             //$target_path = "F:" . '/uploaded/';
            for($i=0;$i<count($_FILES['ad']['name']);$i++){
            if($_FILES["ad"]["name"])
            {
                $filename = $_FILES["ad"]["name"][$i];
                $source = $_FILES["ad"]["tmp_name"][$i];
                $type = $_FILES["ad"]["type"];
                $name = explode(".", $filename);
                $accepted_types = array('text/html','application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed');
                foreach($accepted_types as $mime_type)
                {
                    if($mime_type == $type)
                    {
                        $okay = true;
                        break;
                    } 
                }
                $continue = strtolower($name[1]) == 'zip' ? true : false;
                if(!$continue) {
                $message = "The file you are trying to upload is not a .zip file. Please try again.";
                }
                $target_path = "F:" . '/uploaded/'.$filename; 
                 // change this to the correct site path
                if(move_uploaded_file($source, $target_path )) {
                $zip = new ZipArchive();
                $x = $zip->open($target_path);
                if ($x === true) {
                $zip->extractTo("F:" . '/uploaded/'); // change this to the correct site path
                $zip->close();
                unlink($target_path);
                }
                $message = "Your .zip file was uploaded and unpacked.";
                } else {    
                $message = "There was a problem with the upload. Please try again.";
                }
            }
        }
            echo "Your .zip file was uploaded and unpacked.";
            $template->main_content = $template->fetch(TEMPLATE_DIR . 'donna1.html');
            break;
        default:
            $template->main_content = $template->fetch(TEMPLATE_DIR . 'donna1.html');
            //$this->assign_values('cmd','uploads');
            $this->assign_values('cmd','upload');
}
}
my html page is
<html>
    <link href="css/style.css" rel="stylesheet" type="text/css">
        <!--<form action="{$path_site}{$index_file}" method="post" enctype="multipart/form-data">-->
<form action="index.php?menu=upload_file&cmd=upload" method="post" enctype="multipart/form-data">
<div id="main">
    <div id="login">
            <br />
            <br />
            Ad No 1:
              <input type="file" name="ad[]" id="ad1" size="10" />  Image(.zip)<input type="file" name="ad[]" id="ad1" size="10" />  Sponsor By : <input type="text" name="ad3" id="ad1" size="25" /> 
              <br />
              <br />
  </div>
</div>
</form>
    </html>