Git Product home page Git Product logo

Comments (3)

tbaddade avatar tbaddade commented on August 17, 2024 2

hast du auch ein Beispiel für rex_media_service::addMedia ?

Hier ein Beispiel um Uploadfiles von YForm zu syncen

$transferUploadFilesToMediaPool = static function(rex_media_category $mediaPoolCategory, rex_yform_manager_dataset $dataset) {
    $uploadFiles = [
        'file_1' => $dataset->getValue('file_1'),
        'file_2' => $dataset->getValue('file_2'),
        'file_3' => $dataset->getValue('file_3'),
        'file_4' => $dataset->getValue('file_4'),
    ];

    $moveFiles = [];
    foreach ($uploadFiles as $uploadDir => $uploadFile) {
        if ('' === $uploadFile) {
            continue;
        }

        $path = rex_path::pluginData('yform', 'manager', 'upload/'.$dataset->getTableName().'/'.$uploadDir.'/'.$dataset->getValue('id').'_'.$uploadFile);

        if (!file_exists($path)) {
            continue;
        }

        $data = [];
        $data['title'] = '';
        $data['category_id'] = $mediaPoolCategory->getId();
        $data['file'] = [
            'name' => $uploadFile,
            'path' => $path,
        ];

        try {
            $data = rex_media_service::addMedia($data, true);
            $moveFiles[] = $data['filename'];

            // addMedia verschiebt die Datei
            // Original erhalten lassen
            rex_file::copy(rex_path::media($data['filename']), $path);

        } catch (rex_api_exception $e) {
            throw new rex_functional_exception($e->getMessage());
        }
    }

    $sql = rex_sql::factory();
    $sql->setTable($dataset->getTableName());
    $sql->setWhere('id = :id', ['id' => $dataset->getId()]);
    $sql->setValue('files', implode(',', $moveFiles));

    if ($sql->update()) {
        return true;
    }

    return false;
};

from tricks.

skerbis avatar skerbis commented on August 17, 2024

huhu ... hast du auch ein Beispiel für rex_media_service::addMedia ?
rex_mediapool_syncFile ist mittlerweile deprecated

from tricks.

alxndr-w avatar alxndr-w commented on August 17, 2024

Sollte vielleicht lieber bei der REDAXO-Doku selbst stehen.

        $data = [];
        $data['title'] = '';
        $data['category_id'] = $category_id;
        $data['file'] = [
            'name' => $filename,
            'path' => $path,
        ];
        rex_media_service::addMedia($data, true);

from tricks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.