Results 1 to 4 of 4

Thread: Upload picture from Cron

  1. #1
    New user
    Join Date
    07-11-17.
    Posts
    3

    Default Upload picture from Cron

    Hi !

    I'm currently work on a Cron task that download picture from another FTP. I easily download file, but i've a lot of difficulties to add a new entry in tl_files list.
    I tried scanUploadFolder function but it add eveything that is in file folder and create new entry for every files so i've got a lot of duplicate..
    I also try to create a SQL Insert Into but my sql seems to not accept binary data.

    Can someone help ?

    Thanks in advance an sorry if i make some mistake with my english !
    Last edited by JimTabularasa; 07/11/2017 at 11:54.

  2. #2
    User tetrijeb's Avatar
    Join Date
    04-19-12.
    Location
    Bosnia&Herzegovina
    Posts
    114

    Default

    Quote Originally Posted by JimTabularasa View Post
    Hi !

    I'm currently work on a Cron task that download picture from another FTP. I easily download file, but i've a lot of difficulties to add a new entry in tl_files list.
    I tried scanUploadFolder function but it add eveything that is in file folder and create new entry for every files so i've got a lot of duplicate..
    I also try to create a SQL Insert Into but my sql seems to not accept binary data.

    Can someone help ?

    Thanks in advance an sorry if i make some mistake with my english !
    First, you can try to check whether file in folder already exists in database. If yes, skip new entry.
    SQL: Check your column type.
    Last edited by tetrijeb; 07/13/2017 at 11:25.

  3. #3
    New user
    Join Date
    07-11-17.
    Posts
    3

    Default

    Thanks ! I've found a solution.
    I post my code, this could help if somenone else have same issu one day.
    PHP Code:
    $strFolder "files/cars/photos"//Folder
    $strFile $matches[0]; //FileName
    $path $strFolder "/" $strFile//Relative Path
    $fpath IMGS $matches[0]; //Full Path
    if (!file_exists($fpath) || md5_file($fpath) != $matches[2]){
     
    $this->getFile($conn_id,$fpath,$matches[1]);//custom function for download file
     
    $md5 md5_file($fpath);
     
    $uuid = \String::UuidToBin($md5);
     
    $db->prepare("INSERT IGNORE INTO tl_files (tstamp, pid, uuid, type, path, extension, hash, name) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")->execute(time(), $uuid$uuid'file'$path'jpg'$md5$strFile);


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

    Default

    But you should do this with methods of \DBAFS https://github.com/contao/core/blob/...ntao/Dbafs.php. So you don't need to juggle around with binary or an sql query.
    Code:
    addResource($strResource, $blnUpdateFolders=true)
    moveResource($strSource, $strDestination)
    copyResource($strSource, $strDestination)
    deleteResource($strResource)
    updateFolderHashes($varResource)
    syncFiles()
    shouldBeSynchronized($strPath)
    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
  •