Results 1 to 17 of 17

Thread: Upload file into tl_news

  1. #1
    New user
    Join Date
    10-03-11.
    Posts
    11

    Beitrag Upload file into tl_news

    I use frontend form to upload files into table tl_news. Then I use news FE modul with news_full template to see files in FE. But on Contao 3.5.25 they disappear, but they come back if I repeat a choice in backend. Where is the problem?

  2. #2
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    Best is always to have the latest Contao version installed when asking for help. You can easily update with [easyupdate3].

    Make sure, that the field tl_news.singleSRC contains a UUID which points to a file dataset in tl_files with the same UUID in tl_files.uuid.

    Maybe you have to use a HOOK e.g. https://docs.contao.org/books/api/ex...eFormData.html to store the correct datasets to the DB.

    You can use the public method addResource() from the DBAFS (database assisted file system) class to accomplish this.
    PHP Code:
    \DBAFS::addResource(...); 
    If you will not do this at all, you maybe can modify your output template to manage the output of files which do not contain a uuid in field tl_news.singleSRC. But this will be bad practice and you will not profit from DBAFS for this files - e.g. you can not rename, or move such a file with filemanager anymore.

    Check your template variables by putting this into your template.
    PHP Code:
    <?php
    $this
    ->showTemplateVars();
    ?>
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

  3. #3
    New user
    Join Date
    10-03-11.
    Posts
    11

    Default

    Is there an example how to get tstamp and uuid if we use forms to store data into tl_news from frontend?

    Tnx

  4. #4
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    This is done automaticaly if you use the upload field in formgenerator. So you will find examples in the core.
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

  5. #5
    New user
    Join Date
    10-03-11.
    Posts
    11

    Default

    I use upload field but obviously something goes wrong. Could be a problem with name....I called her "enclosure"?

  6. #6
    User Spooky's Avatar
    Join Date
    01-03-13.
    Posts
    339

    Default

    Quote Originally Posted by Andreas View Post
    This is done automaticaly if you use the upload field in formgenerator. So you will find examples in the core.
    This is not true. The form generator will always save the path to the file, not UUIDs.

    You can use store_uuid to automatically store the UUID though.

  7. #7
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    Oh, yes, you're right. I only looked into tl_files where I found the uuid.

    But in my target table "files" only the path of the folder is saved into "files.files" ("files/files-test" - same field-type as tl_files.uuid). With your store_uuid 1.0.1 and also without it. What am I doing wrong here?
    Last edited by Andreas; 09/04/2017 at 11:11.
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

  8. #8
    User Spooky's Avatar
    Join Date
    01-03-13.
    Posts
    339

    Default

    Post the DCA of your table.

  9. #9
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    This table has no DCA. It's beside Contao.
    Code:
    CREATE TABLE `files` (
    	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    	`tstamp` INT(10) UNSIGNED NOT NULL DEFAULT '0',
    	`files` BINARY(16) NULL DEFAULT NULL,
    	PRIMARY KEY (`id`)
    )
    COLLATE='utf8_general_ci'
    ENGINE=MyISAM
    ROW_FORMAT=DYNAMIC
    AUTO_INCREMENT=9
    ;
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

  10. #10
    User Spooky's Avatar
    Join Date
    01-03-13.
    Posts
    339

    Default

    That's why store_uuid is not working. It needs the DCA information.

  11. #11
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    Ah, ok. If I save to tl_content.singleSRC it works. But shouldn't it also work in new tables without "tl_"?
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

  12. #12
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    And why only the path without the filename gets saved (without your extension)? Is this a Contao bug? It saves
    "files/files-test"
    instead
    "files/files-test/myImg.jpg"
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

  13. #13
    User Spooky's Avatar
    Join Date
    01-03-13.
    Posts
    339

    Default

    Quote Originally Posted by Andreas View Post
    Ah, ok. If I save to tl_content.singleSRC it works. But shouldn't it also work in new tables without "tl_"?
    As I said, the extension (currently) needs the DCA info for the target table in order to determine whether or not to save the file as an UUID instead of the path. Forcing it to UUID would be an additional feature that I could implement.



    Quote Originally Posted by Andreas View Post
    And why only the path without the filename gets saved (without your extension)? Is this a Contao bug? It saves
    "files/files-test"
    instead
    "files/files-test/myImg.jpg"
    As mentioned on IRC: are you still using your BINARY(16) field for that? If yes - that field cannot hold long path names.

  14. #14
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    Yes, thank you, it was the wrong field configuration "files/files-test" was coincidentally exact 16 chars long.

    No problem, we can use a DCA for "tl_myfiles" if we only would know this fact. But adding this feature also would be great so one can use tables without "tl_".
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

  15. #15
    New user
    Join Date
    10-03-11.
    Posts
    11

    Default

    I solved my problem with store_uuid, and now I have secound problem with tstamp...how to store correct date...I always get 1.1.1970 .

  16. #16
    New user
    Join Date
    10-03-11.
    Posts
    11

    Default

    UPS...i did't, with insert tag {{date:U}}.

  17. #17
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    You get the timestamp with time().
    PHP Code:
    echo time(); 
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •