Skip to content

Externe Datei (URL) in den Medienpool importieren mit Titel etc. #7

Answered by eaCe
skerbis asked this question in Q&A
Discussion options

You must be logged in to vote

Hier ein Beispiel mit einem einfachen Titel => URL Array:

$images = [
    'Title 1' => 'https://images.pexels.com/photos/7488465/pexels-photo-7488465.jpeg',
    'Title 2' => 'https://images.pexels.com/photos/6441504/pexels-photo-6441504.jpeg'
];

foreach ($images as $title => $url) {
    /** Dateiname aus der URL holen */
    $baseName = basename($url);

    /** Medienpool-Name erstellen */
    $fileName = rex_mediapool::filename($baseName, false);

    /** check ob die Datei noch nicht existiert */
    if (rex_media::get($fileName) === null) {
        $mediaPath = rex_path::media($fileName);

        /** Bild von URL laden */
        $image = rex_socket::factoryUrl($url)->doGet();

        

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by skerbis
Comment options

skerbis
Jul 6, 2022
Maintainer Author

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants