File upload error 'A server error occurred while uploading the file'

File upload error 'A server error occurred while uploading the file'

Koen VerhoevenKoen Verhoeven Posts: 25Questions: 7Answers: 0

I've been trying to create a simple single file upload. But I keep getting the error 'A server error occurred while uploading the file'

My js file contains the following code where the table name is called 'deenk_files' and the primary key of the table is file_id


{ label: "Image:", name: "image", type: "upload", display: function ( file_id ) { return '<img src="'+editor.file( 'deenk_files', file_id ).web_path+'"/>'; }, clearText: "Clear", noImageText: 'No image' }

My php file contains the following code.

Field::inst( 'image' )
            ->setFormatter( Format::ifEmpty( null ) )
            ->upload( Upload::inst( 'D:\data/test.png' )
                ->db( 'deenk_files', 'file_id', array(
                    'filename'    => Upload::DB_FILE_NAME,
                    'filesize'    => Upload::DB_FILE_SIZE,
                    'web_path'    => Upload::DB_WEB_PATH,
                    'system_path' => Upload::DB_SYSTEM_PATH
                ) )
            )

Any idea what is going wrong here?

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    You need to check your server error logs to see exactly what the error is.

  • Koen VerhoevenKoen Verhoeven Posts: 25Questions: 7Answers: 0
    edited August 2019

    The only error I can find is the following

    SQLite3::query(): Unable to prepare statement: 1, incomplete input in D:\Kaartviewer\sqlite3\sqlite3.php on line 36
    

    Which is strange since I'm not using sqlite at this point.

    At line 36 I found the following code:


    function sqlite_query($dbhandle,$query) { // Detect number of tables in the query. // like 'SELECT * FROM table1,table2' // 1. When more then one table is found we have to add the tablename to the result set. // 2. If an astrix is found in the SELECT if (preg_match('/^(select|update|insert|delete)(.+?from| into)?\\s*`?(.+?)($|`| |\\()/i', strtolower($query), $result)) { $enable = (strpos($result[0], "*") > -1 && count(explode(",", $result[3])) > 1); $dbhandle->exec(sprintf('PRAGMA full_column_names = %s;', $enable ? '1' : '0' )); $dbhandle->exec(sprintf('PRAGMA short_column_names = %s;', $enable ? '0' : '1' )); } return $dbhandle->query($query); //this is line 36 }
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    That doesn't appear to be the code with publish for the Editor PHP libraries. I'm not at all sure where that sqlite_query function is defined. Is that one of your own, or some other third party libraries?

    For the upload, when you upload the file, what does the server respond with (the browser's network inspector tools will show you).

    Allan

  • Koen VerhoevenKoen Verhoeven Posts: 25Questions: 7Answers: 0

    It is a third party library I use as part of the website where I also use datatables. The only errors I get are:
    A server error occurred while uploading the file
    and the server is showing:
    SQLite3::query(): Unable to prepare statement: 1, incomplete input in D:\Kaartviewer\sqlite3\sqlite3.php on line 36

    Any other errors I did not find.

    So if I understand correctly the script for the file upload tries to use an existing function with the same name from the third party library? Any idea in which direction I have to look?

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Answer ✓

    I would start with a test case which excludes the third-party library. That should immediately tell you whether this is a DataTables problem.

  • Koen VerhoevenKoen Verhoeven Posts: 25Questions: 7Answers: 0

    Sorry for the late reply, I missed the email notification with your answer.
    You are totally right. When creating a complete new table with the generator, and trying it again, it works perfectly.

This discussion has been closed.