Getting warnings with editor file upload

Getting warnings with editor file upload

mRendermRender Posts: 151Questions: 26Answers: 13

I'm getting a couple of warnings on my first try on the file upload. I get a couple of warnings about calls to the upload function when I try to add a file to the editor.

include( "DataTables-1.10.7/extensions/Editor-1.4.2/php/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;

$data = Editor::inst( $db, 'files', 'FID' )
    ->field(
        Field::inst( 'files.FID' ),
        Field::inst( 'files.file_id' )
            ->options( 'parts', 'part_id', 'fgc_number' ),
        Field::inst( 'files.path' )
            ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/uploads/__ID__.__EXTN__' ) )
    )
    ->LeftJoin( 'parts', 'parts.part_id', '=', 'files.file_id' )
    ->process($_POST)
    ->data();

 
// Send it back to the client
echo json_encode( $data );

Here is my js

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        processing: true,
        serverSide: true,
        ajax: "dt_files.php",
        table: "#files",
        fields: [  {
                label: "FID:",
                name: "files.FID"
            },{
                label: "file_id:",
                name: "files.file_id",
                type: "select"
            },{
                label: "path:",
                name: "files.path",
                type: "upload"
            }
        ]
    } );
    
    
    $('#files').DataTable( {
        dom: "Tfrtip",
        pageLength: 25,
        paging: true,
        info: false,
        idSrc: "files.FID",
        ajax: "dt_files.php",
        columns: [
            { data: "files.FID" },
            { data: "files.file_id" },
            { data: "files.path" }
        ],
        "order": [[ 0, 'asc' ]],
        
        tableTools: {
            sRowSelect: "os",
            sSwfPath: "DataTables-1.10.7/extensions/TableTools/swf/copy_csv_xls_pdf.swf",
            aButtons: [
                { sExtends: "editor_create",   editor: editor },
                { sExtends: "editor_edit",   editor: editor },
                { sExtends: "editor_remove", editor: editor },
                "print",
                {
                    "sExtends":    "collection",
                    "sButtonText": "Save",
                    "aButtons":    [ "csv", "xls", "pdf" ]}
            ]
        }
    } );
} );

Here is the website if you want to take a look at the warnings.

http://162.211.86.176/catalog/index.php

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin

    Warning: move_uploaded_file(...): failed to open stream: No such file or directory in

    Sounds like the uploads directory might not exist in your host's virtual root. Does it?

    Also if you want to use __ID__ you need to use the Upload->db() method to tell it information about the database table you want to store the file information in (otherwise the id won't exist!).

    Allan

  • mRendermRender Posts: 151Questions: 26Answers: 13

    Whoops.

            ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/uploads/__ID__.__EXTN__' ) )
    

    Should have been

            ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/catalog/uploads/__ID__.__EXTN__' ) )
    

    And I just turned it into this:

            ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/catalog/uploads/__NAME__' ) )
    

    That should suffice with that I need to do here.

    I'm also having an issue with webPath being undefined. I'm trying to implement this code here:

    {
                    label: "path:",
                    name: "files.path",
                    type: "upload",
                    display: function ( val, row ) {
                     return val && row.image.webPath ?
                         '<img src="'+row.image.webPath+'"/>' :
                         'No image';
                 }
               }
    

    Is there something else that I need to do? When I add an image in the editor it throws the webPath undefined error.

  • mRendermRender Posts: 151Questions: 26Answers: 13
    edited May 2015

    I tried something like this to get the webPath and added fileName, fileSize and webPath to my database but I'm still getting webPath errors.

    $data = Editor::inst( $db, 'files', 'FID' )
        ->field(
            Field::inst( 'files.FID' ),
            Field::inst( 'files.file_id' )
                ->options( 'parts', 'part_id', 'fgc_number' ),
            Field::inst( 'parts.file1' )
            ->upload(
            Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/catalog/uploads/__NAME__' )
                ->db( 'files', 'FID', array(
                    'fileName' => Upload::DB_FILE_NAME,
                    'fileSize' => Upload::DB_FILE_SIZE,
                    'webPath' => Upload::DB_WEB_PATH
                ) )
        ) )
        ->LeftJoin( 'parts', 'parts.part_id', '=', 'files.file_id' )
        ->process($_POST)
        ->data();
    
  • mRendermRender Posts: 151Questions: 26Answers: 13

    WHOOPS! Got it.

    {
                    label: "path:",
                    name: "parts.file1",
                    type: "upload",
                    display: function ( val, row ) {
                         return val && row.files.webPath ?
                             '<img src="'+row.files.webPath+'"/>' :
                             'No image';
                     },
                   }
            ]
        } );
    

    I was using image.webPath instead of my table name of files. I'm an idiot.

    Good work Allan on the file uploader. Some pretty cool stuff here!

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin
    Answer ✓

    Hi,

    Great to hear you've got it working now! Upload is certainly one of the more complicated parts of Editor - there was only so much complexity that I was comfortable with abstracting out (a trade off between flexibility and the initial learning curve).

    Allan

This discussion has been closed.