by
geracar
Uploaded in
Debes iniciar sesión para subir archivos.";
}
ob_start();
// Procesar subida
if (isset($_POST['unirem_upload'])) {
require_once(ABSPATH . 'wp-admin/includes/file.php');
$uploadedfile = $_FILES['file'];
$upload_overrides = array('test_form' => false);
$movefile = wp_handle_upload($uploadedfile, $upload_overrides);
if ($movefile && !isset($movefile['error'])) {
$filetype = wp_check_filetype($movefile['file'], null);
$attachment = array(
'post_mime_type' => $filetype['type'],
'post_title' => sanitize_file_name($uploadedfile['name']),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment($attachment, $movefile['file']);
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata($attach_id, $movefile['file']);
wp_update_attachment_metadata($attach_id, $attach_data);
echo "Archivo subido correctamente.
";
} else {
echo "Error al subir archivo.
";
}
}
?>
'attachment',
'post_status' => 'inherit',
'posts_per_page' => -1,
);
$attachments = get_posts($args);
foreach ($attachments as $attachment) {
$url = wp_get_attachment_url($attachment->ID);
$mime = get_post_mime_type($attachment->ID);
echo "
";
if (strpos($mime, 'image') !== false) {
echo wp_get_attachment_image($attachment->ID, 'thumbnail');
} else {
echo "
📄
";
}
echo "
{$attachment->post_title}
";
echo "
Descargar";
echo "
";
}
echo "
";
return ob_get_clean();
}
More by the same author