1. Hello Guest, selamat datang di Forum WinPoin. Kamu bisa bertanya, berdiskusi, sharing, dan ngobrolin apapun seputar Windows, Windows Phone, PC, Gadget, atau hal seputar Teknologi lainnya. Selamat berkomunitas! ;)

Jtable Upload Image

Discussion in 'Developer Corner' started by bancad, May 7, 2014.

  1. bancad

    bancad New Member

    Joined:
    May 7, 2014
    Messages:
    4
    Selamat Sore om... saya mau tanya masalah plugin Jtable yang ada di Jtable.org

    saya mencoba membuat function script upload file/image di jtable namun selalu terjadi error / data tidak masuk ke Mysql... Berikut file Javascript dari Jtable

    Code:
    <?php
    session_start();
     if (empty($_SESSION['username']) AND empty($_SESSION['passuser'])){
      echo "<link href='style.css' rel='stylesheet' type='text/css'>
     <center>Untuk mengakses modul, Anda harus login <br>";
      echo "<a href=../../index.php><b>LOGIN</b></a></center>";
    }
    else{
    ?>
    		
    			
    <script type="text/javascript">
    
    		$(document).ready(function () {
    			
    			
    		    //Prepare jTable
    			$('#PeopleTableContainer').jtable({
    			
    				title: 'Table of Gallery',
    				paging: true,
    				pageSize: 5,
    				sorting: true,
    				defaultSorting: 'name ASC',
    				selecting: true, //Enable selecting
    				multiselect: true, //Allow multiple selecting
    				selectingCheckboxes: true, //Show checkboxes on first column
    				
    								
    				actions: {
    					listAction: 'modul/mod_gallery/GalleryActions.php?action=list',
    					createAction: 'modul/mod_gallery/GalleryActions.php?action=create',
    					updateAction: 'modul/mod_gallery/GalleryActions.php?action=update',
    					deleteAction: 'modul/mod_gallery/GalleryActions.php?action=delete'
    
    				},
    				
    				fields: {
    					id_title_gallery: {
    						key: true,
    						create: false,
    						edit: false,
    						list: false
    					},
                 
                    //CHILD TABLE DEFINITION FOR "EXAMS"
                    Exams: {
                        title: '',
    					
                        width: '1%',
                        sorting: false,
                        edit: false,
                        create: false,
    					
                        display: function (asd) {
                            //Create an image that will be used to open child table
                            var $img = $('<img src="Codes/child.png" title="Child" />');
                            //Open child table when user clicks the image
                            $img.click(function () {
    							
                                $('#PeopleTableContainer').jtable('openChildTable',
    							
                                        $img.closest('tr'), //Parent row
                                        {
                                        title: asd.record.name + ' - Child',
    									
    									selecting: true, //Enable selecting
    									multiselect: true, //Allow multiple selecting
    									selectingCheckboxes: true, //Show checkboxes on first column
    									paging: true,
    									pageSize: 5,
    									sorting: true,
    									defaultSorting: 'gambar ASC',
                                        actions: {
                                            listAction: 'modul/mod_gallery/child.php?action=cek&id_title_gallery=' + asd.record.id_title_gallery ,
                                            deleteAction: '/Demo/DeleteExam',
                                            updateAction: '/Demo/UpdateExam',
                                            createAction: 'modul/mod_gallery/child.php?action=create&id_title_gallery=' + asd.record.id_title_gallery
                                        },
                                        fields: {
                                            id_title_gallery: {
                                                    type: 'hidden',
                                                    defaultValue: asd.record.id_title_gallery
                                                },
                                            id_gal: {
                                                key: true,
                                                create: false,
                                                edit: false,
                                                list: false
                                            },
                                            nama_gambar: {
                            title: 'Album cover',
                            list: true,
                            create: true,
                            edit: true,
                            input: function(data) {
                                return '<form target="iframeTarget" class="formUploadFile" action="modul/mod_gallery/child.php?action=create" method="post" enctype="multipart/form-data"> <input type="file" onchange="this.form.submit()" name="as"/> </form> <iframe class="upload-iframe" style="display: none;" src="#" name="iframeTarget"></iframe>';
                            }
                        },
    
    						gambar: {
                            title: 'Album cover',
                            list: true	,
                            create: true,
                            edit: true,
                            input: function(data) {
                                html = '<input type ="text" id="nama_gambar" name="nama_gambar" />';
                                return html;
                            }
                        },
                                            sort: {
                                                title: 'Sort',
                                                width: '5%'
                                            },
                                            aktif: {
                                                title: 'Aktif',
                                                width: '10%',
    											type: 'checkbox',
    											values: { '0': 'InActive', '1': 'Active' },
    										defaultValue: '0'
    											
                                            },
    										tanggal: {
    											title: 'Record date',
    											width: '10%',
    											type: 'date',
    											create: false,
    											edit: false
    										},
    										creator:{
    												title: 'Creator',
    												width: '20%',
    												create: false,
    												edit: false
    												}
                                        },
    									formSubmitting: function(event, data) {
                        filename = $('input[type=file]').val().split('\\').pop();
                        ($("#" + data.form.attr("id")).find('input[name="gambar"]').val(filename));
    					
    						}
    								
                                    }, function (data) { //opened handler
                                        data.childTable.jtable('load');
                                    });
                            });
                            //Return image to show on the person row
                            return $img;
                        }
                    },
    				name:{
    						title: 'Name',
    						width: '20%',
    
    
    
    					},
    				sort:{
    						title: 'Sort',
    						width: '1%'
    
    
    					},
    				aktif:{
                            title: 'Aktif',
                            width: '10%',
    						type: 'checkbox',
    						values: { '0': 'InActive', '1': 'Active' },
    						defaultValue: '0'
    						},
    				tanggal: {
    						title: 'Record date',
    						width: '10%',
    						type: 'date',
    						create: false,
    						edit: false
    					},
    				creator:{
    						title: 'Creator',
    						width: '20%',
    						create: false,
    						edit: false
                          
    						}
    
    
    
    				}
    				
    			});
    
    			//Load person list from server
    			$('#PeopleTableContainer').jtable('load');
    
    		});
    
    	</script>
    <?php 
    switch($_GET[act]){
    //tampil
      default:?>
     
       <div id='bgwrap'>
       <div id='content'>
    					<div id='main'>
    	<div id="PeopleTableContainer" style="width: 900px;"></div>
    	
     
      <?php
    	echo "</div></div> ";
    	break;
    } }
    ?>
    

    dan untuk penerima File nya di php

    Code:
    else if($_GET["action"] == "create")
    	{	
    		$gambar = $_POST["nama_gambar"];
    		$filename = $_FILES['as']['tmp_name'];  
    		$destination = "../../../img/logo_partner/" . $_FILES['as']['name'];  
    		$asd = $_FILES['as']['name'];
    		$id_title = $_POST["id_title_gallery"]; 
    	if (empty($filename)) {  
    	echo"Upload gallery dulu dong...!";  
    	}
    	 else {  
    
    		if (move_uploaded_file($filename, $destination)) {  
    		//Insert record into database
    		$result = mysql_query("INSERT INTO frontpage_gallery(id_title_gallery, nama_gambar, gambar, sort, aktif, creator) VALUES('" . $id_title . "','" . $_POST["nama_gambar"] . "','" . $asd . "', '" . $_POST["sort"] . "', '" . $_POST["aktif"] . "', '" .  $_SESSION["username"] . "')");
    		
    		//Get last inserted record (to return to jTable)
    		$result = mysql_query("SELECT * FROM frontpage_gallery WHERE id_gal = LAST_INSERT_ID();");
    		$row = mysql_fetch_array($result);
    
    		//Return result to jTable
    		$jTableResult = array();
    		$jTableResult['Result'] = "OK";
    		$jTableResult['Record'] = $row;
    		print json_encode($jTableResult);
    	}
    	else {  
    	echo"gallery gagal diupload"; 
    	} 
    	}
    	}

    atau kalau sudah ada yang pernah mencoba jtable dari jtable.org boleh share untuk pencerahannya ?? Jujur saja digoogle sudah saya ubek" di github nya pun juga sama... namun jawabannya selalu nihil
     
  2. marwanto.se

    marwanto.se New Member

    Joined:
    May 7, 2013
    Messages:
    7,659
    Halo bancad, sebelumnya salam kenal & selamat bergabung di forum WinPoin.
    Semoga betah ya main di sini?, baca juga panduan berkomunitas serta patuhi rules yang berlaku. :goodjob:

    [hr]

    Saya sih belum pernah nyoba gituan selama membuat web blog, coba tanyakan ke sob SabunColek karena dia lebih tahu soal programming website & forum? :ketawa:
     
  3. Jazz

    Jazz Super Moderatór Staff Member

    Joined:
    Jan 6, 2014
    Messages:
    14,731
    Error apa ini yg Keluar?
    Pastikan Destinasinya benar..
     
  4. Ambrizal Suryadinata

    Ambrizal Suryadinata Saya Ganteng Staff Member

    Joined:
    Jan 25, 2014
    Messages:
    2,587
    Screenshotnya please mas bro.
    Mau tanya itu naruh databasenya dibelakang root itu ye.
     
  5. bancad

    bancad New Member

    Joined:
    May 7, 2014
    Messages:
    4
    terima kasih om... amin.. insya ALLAH betah... :sokganteng:




    jadi gini om... ketika saya tambahkan
    Code:
    onchange="this.form.submit()"
    di file js line 97... file image masuk ke folder tpi ke database nya ngga... tapi tetap error

    ini screenshootnya
    [​IMG]

    dan ini masuk ke destination nya (folder yang dituju)
    [​IMG]


    nah tapi kalo saya hapus
    Code:
    onchange="this.form.submit()"
    di file js line 97 file image masuk kedatabase tpi tidak masuk ke destination folder yang dituju.. dan terjadi error
    [​IMG]
    [​IMG]


    maksudnya di belakang root om ???

    saya udah hampir seminggu stuck disini om mumet ngubek" google sama aja nihil belom dpt pencerahan :galau2:
     
  6. Jazz

    Jazz Super Moderatór Staff Member

    Joined:
    Jan 6, 2014
    Messages:
    14,731
    Aku Butuh Kaca Pembesar untuk Melihatnya (Kecil Bingit)
    :woa:
     
  7. bancad

    bancad New Member

    Joined:
    May 7, 2014
    Messages:
    4
    udah mentok om itu size nya,,, :desperate2: coba di view image aja om :desperate2:
     
  8. stefanus aggasia

    stefanus aggasia Active Member

    Joined:
    Nov 8, 2013
    Messages:
    3,004
    belum nyampe segitu sob aku ngoprek blog :goodjob:
     
  9. Jazz

    Jazz Super Moderatór Staff Member

    Joined:
    Jan 6, 2014
    Messages:
    14,731
    Ora po po deh di Panggil Om
    :nangis3:

    Anyway, aku ndak Pernah main di php...
    XAMPP ya

    Cek Ricek Source codenya...
    Perkiraanku, ada Barisan Code yg Block itu Gambar buat Showoff
    *Detailnya Aku Kurang Paham, tp yg Jelas Coba Cek Ricek dlu Codingnya
     
  10. Ambrizal Suryadinata

    Ambrizal Suryadinata Saya Ganteng Staff Member

    Joined:
    Jan 25, 2014
    Messages:
    2,587
    Coba gini :

    Code:
    <input type="file" onchange="this.form.submit()" name="asd"/> </form>
    
    itu name asd saya dapatkan dari code yang kamu buat pada bagian $asd.

    Code:
    		$gambar = $_POST["nama_gambar"];
    		$filename = $_FILES['as']['tmp_name'];  
    		$destination = "../../../img/logo_partner/" . $_FILES['as']['name'];  
    		$asd = $_FILES['as']['name'];
    		$id_title = $_POST["id_title_gallery"]; 
    
     
  11. bancad

    bancad New Member

    Joined:
    May 7, 2014
    Messages:
    4
    tetep ga bisa om.. ga masuk juga ke database sama ke direktori foldernya :desperate2:


    bukannya kalo di
    Code:
    <input type="file" onchange="this.form.submit()" name="asd"/> </form>
    
    name="asd" berarti kan di $_FILES['asd'] bukannya $_FILES['as'] kan ?
     
  12. Ambrizal Suryadinata

    Ambrizal Suryadinata Saya Ganteng Staff Member

    Joined:
    Jan 25, 2014
    Messages:
    2,587
    Wah iya ya agak lupa saya :ketawa:
    ntar aku cek dulu.
     

Share This Page