| Server IP : 202.61.199.114 / Your IP : 216.73.217.139 Web Server : nginx/1.22.1 System : Linux de.arni-solutions.de 6.1.0-49-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.174-1 (2026-05-26) x86_64 User : web20 ( 1018) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /proc/3951577/root/tmp/ |
Upload File : |
<?php
require '/var/www/clients/client2/web20/web/wp-load.php';
require_once ABSPATH . 'wp-admin/includes/image.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/media.php';
$images = array(
array(
'file' => '/tmp/unsplash-images/cannabis-hero.jpg',
'title' => 'Cannabis Pflanze – Beitragsbild',
'alt' => 'Cannabis-Pflanze – Die besten Reiseziele für Cannabis-Touristen in Europa',
'caption' => 'Foto: Jose Luis Sanchez Pereyra / Unsplash',
'desc' => 'Beitragsbild für den Artikel über Cannabis-Reiseziele in Europa. Foto: Jose Luis Sanchez Pereyra via Unsplash (Unsplash License).',
'key' => 'hero',
),
array(
'file' => '/tmp/unsplash-images/amsterdam-grachten.jpg',
'title' => 'Amsterdam Grachten – Niederlande',
'alt' => 'Amsterdam Grachten mit historischen Häusern – Niederlande sind Europas Nummer eins für Cannabis-Touristen',
'caption' => 'Amsterdam: Die Grachtenstadt bleibt Europas Nummer eins für Cannabis-Touristen. Foto: Tobias Reich / Unsplash',
'desc' => 'Historische Grachtenhäuser in Amsterdam. Foto: Tobias Reich via Unsplash (Unsplash License).',
'key' => 'amsterdam',
),
array(
'file' => '/tmp/unsplash-images/barcelona-cityscape.jpg',
'title' => 'Barcelona Stadtansicht mit Sagrada Família – Spanien',
'alt' => 'Barcelona Stadtansicht mit Sagrada Família – Cannabis Social Clubs machen Spanien zum Top-Reiseziel',
'caption' => 'Barcelona: Hunderte Cannabis Social Clubs machen die Stadt zur CSC-Hauptstadt Europas. Foto: Davit Margaryan / Unsplash',
'desc' => 'Stadtansicht von Barcelona mit der Sagrada Família. Foto: Davit Margaryan via Unsplash (Unsplash License).',
'key' => 'barcelona',
),
array(
'file' => '/tmp/unsplash-images/lissabon-tram.jpg',
'title' => 'Straßenbahn in Lissabon – Portugal',
'alt' => 'Gelbe Straßenbahn in Lissabon – Portugals Entkriminalisierung aller Drogen seit 2001 gilt weltweit als Vorbild',
'caption' => 'Lissabon: Portugals Entkriminalisierung aller Drogen seit 2001 gilt weltweit als Vorbild. Foto: Sarah Markstaller / Unsplash',
'desc' => 'Gelbe Straßenbahn in einer Straße in Lissabon. Foto: Sarah Markstaller via Unsplash (Unsplash License).',
'key' => 'lisbon',
),
array(
'file' => '/tmp/unsplash-images/valletta-malta.jpg',
'title' => 'Valletta Waterfront – Malta',
'alt' => 'Valletta Malta – erstes EU-Land mit Cannabis-Legalisierung für den Freizeitkonsum',
'caption' => 'Valletta: Malta war das erste EU-Land, das Cannabis für den Freizeitkonsum legalisierte. Foto: Sarolta Balog-Major / Unsplash',
'desc' => 'Historische Hafenfront von Valletta, Malta. Foto: Sarolta Balog-Major via Unsplash (Unsplash License).',
'key' => 'malta',
),
);
$attachment_ids = array();
foreach ($images as $img) {
$file = $img['file'];
if (!file_exists($file)) {
echo "FEHLT: {$file}\n";
continue;
}
$upload_dir = wp_upload_dir();
$filename = basename($file);
$dest = $upload_dir['path'] . '/' . $filename;
copy($file, $dest);
$filetype = wp_check_filetype($filename);
$attachment = array(
'post_mime_type' => $filetype['type'],
'post_title' => $img['title'],
'post_content' => $img['desc'],
'post_excerpt' => $img['caption'],
'post_status' => 'inherit',
);
$attach_id = wp_insert_attachment($attachment, $dest);
if (is_wp_error($attach_id)) {
echo "FEHLER bei {$img['key']}: " . $attach_id->get_error_message() . "\n";
continue;
}
$attach_data = wp_generate_attachment_metadata($attach_id, $dest);
wp_update_attachment_metadata($attach_id, $attach_data);
update_post_meta($attach_id, '_wp_attachment_image_alt', $img['alt']);
$attachment_ids[$img['key']] = $attach_id;
$url = wp_get_attachment_url($attach_id);
echo "{$img['key']}: ID={$attach_id} URL={$url}\n";
}
// Set featured image
if (isset($attachment_ids['hero'])) {
set_post_thumbnail(1300, $attachment_ids['hero']);
echo "\nBeitragsbild gesetzt: ID={$attachment_ids['hero']}\n";
}
// Output all IDs for post content update
echo "\n=== ATTACHMENT IDS ===\n";
foreach ($attachment_ids as $key => $id) {
$url = wp_get_attachment_url($id);
echo "{$key}={$id}|{$url}\n";
}