upload photo

upload photo

maxstdmaxstd Posts: 6Questions: 2Answers: 0
edited June 2015 in Plug-ins

Friends, please, help! my brain is broken!!!

I have two tables . Table 1 (emploee) - id, name, photo. Table 2 (photo) - id, photo.
Both tables are empty. I can not upload a photo to display it in table 1.
when I load a picture , an error - Unknown upload field name submitted.

Then A system error has occurred (More information).

What am i doing wrong?

<?php

/*
 * Editor server script for DB table staffsubdepartment
 * Created by http://editor.datatables.net/generator
 */

// DataTables PHP library and database connection
include( "lib/DataTables.php" );

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Join,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate;
Editor::inst( $db, 'emploee')
    ->field(
        Field::inst( 'name' ),
        Field::inst( 'photo' )
    )
    ->process( $_POST )
 ->json();


$(document).ready(function() { var editor = new $.fn.dataTable.Editor( { ajax: "php/emploee.php", table: "#emploee", fields: [ { label: "Info:", name: "info", type: "upload" } ] } ); $('#emploee').DataTable( { dom: "Tfrtip", ajax: "php/emploee.php", columns: [ { data: "name" }, { data: "title" }, { data: "photo.photo", defaultContent: "No image", render: function ( d ) { return d.webPath ? '<img src="'+d.webPath+'"/>' : null; } }, ], tableTools: { sRowSelect: "os", aButtons: [ { sExtends: "editor_create", editor: editor }, { sExtends: "editor_edit", editor: editor }, { sExtends: "editor_remove", editor: editor } ] } } ); } );

Maksim

This question has an accepted answers - jump to answer

Answers

  • mRendermRender Posts: 151Questions: 26Answers: 13
    Answer ✓

    Your javascript should be:

    {
                    label: "Photo:",
                    name: "employee.photo",
                    type: "upload"
                },
    

    Your server side page should be:

    Field::inst( 'employee.photo' )
            ->upload(
            Upload::inst( $_SERVER['DOCUMENT_ROOT'].'__NAME__' )
                ->db( 'photo', 'photo.id', array(
                    'photo.photo' => Upload::DB_FILE_NAME,
                ) ) ),
    

    The editor puts the photo.id id into the employee photo column in your database. You also have to give the javascript a type of upload to tell it that it is supposed to be an upload field.

  • maxstdmaxstd Posts: 6Questions: 2Answers: 0
    edited June 2015

    Modgility,thanks for the answer!

    But,I get an error:
    SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM photo WHERE photo.id = '0'' at line 1

    <?php
    include( "lib/DataTables.php" );
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Join,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    Editor::inst( $db, 'emploee','id' )
        ->field(
        Field::inst( 'emploee.name' ),
    Field::inst( 'emploee.photo' )
            ->upload(
            Upload::inst( $_SERVER['DOCUMENT_ROOT'].'__NAME__' )
                ->db( 'photo', 'photo.id', array(
                    'photo.photo' => Upload::DB_FILE_NAME,
                ) ) ),
        )
        ->leftJoin( 'photo', 'photo.id', '=', 'emploee.photo' )
        ->process($_POST)
        ->json();
    
    (function($){
    
    $(document).ready(function() {
        var editor = new $.fn.dataTable.Editor( {
            "ajax": "php/emploee.php",
            "table": "#emploee",
            "fields": 
            [
                {label: "name:",name: "emploee.name"},
                {label: "Photo:",name: "emploee.photo",type: "upload"}
            ]
    } );
     
    $('#emploee').DataTable( {
       dom: "Tfrtip",
       ajax: "php/emploee.php",
       columns: 
       [
               {data: "emploee.name"},
               {data: "emploee.photo"}
        ],
       tableTools: {
           sRowSelect: "os",
           aButtons: [
               { sExtends: "editor_create", editor: editor },
               { sExtends: "editor_edit",   editor: editor },
               { sExtends: "editor_remove", editor: editor }
           ]
            }
        } );
    } );
    }(jQuery));
    
    

    thanks again!

    Спасибо еще раз!

  • mRendermRender Posts: 151Questions: 26Answers: 13

    That looks a LOT better. Unfortunately, without a test page that I can view, my helping skills end here. If you have a test page let me know and I'll take a look at it for you. At least you're really close now!

  • maxstdmaxstd Posts: 6Questions: 2Answers: 0

    Modgility,I solved the problem with an error.

    written on one site - from is a keyword in SQL. You may not used it as a column name without quoting it. In MySQL, things like column names are quoted using backticks, ie from.

    but I also can not link the two tables . Table which should contain information about the photo (path , file extension ) remains empty.because this communication not working preview photos

        var editor = new $.fn.dataTable.Editor( {
            "ajax": "php/emploee.php",
            "table": "#emploee",
            "fields": 
            [
                {label: "name:",name: "emploee.name"},
                {label: "Photo:",name: "emploee.photo",type: "upload",
                     display: function ( val, row ) {
             return val && row.image.webPath ?
                 '<img src="'+row.image.webPath+'"/>' :
                 'No image';
         },}
            ]
    } );
    

    ever written - "No image"

This discussion has been closed.