• Resolved amministratore01pi

    (@amministratore01pi)


    Hi, I created a file upload page, with the WpForms plugin. This page inserts these files into a folder that has the same name as the user who registered on the site.
    I need to create a page that can display (or possibly even delete) these files based on the user who registered on the site.
    Can someone help me?..
    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • graphicscove

    (@graphicscove)

    To create a page that displays files based on the logged-in user, you can try the following –

    // Get the current user
    $current_user = wp_get_current_user();
    $user_folder = $current_user->user_login; // Assuming the folder is named after the username

    // Then use the following to get the user files from the folder
    $directory = wp_upload_dir()['basedir'] . '/your-upload-folder/' . $user_folder;
    $files = scandir($directory);

    foreach ($files as $file) {
    if ($file !== '.' && $file !== '..') {
    echo '<a href="' . wp_upload_dir()['baseurl'] . '/your-upload-folder/' . $user_folder . '/' . $file . '">' . $file . '</a><br>';
    }
    }

    You could then add a form/button next to each result to trigger the delete functionality, but you’ll need to be aware of permissions! Let me know if you need a hand with some demo code for deleting as well.

    Thread Starter amministratore01pi

    (@amministratore01pi)

    Hi,
    first of all thanks for your reply.
    Excuse my ignorance.. but where should I use what you passed me? In a new page that I create?..
    Thanks

    graphicscove

    (@graphicscove)

    You’ll need to add the code above to your theme, preferably on a new page template, and then set a page to use that page template.

    It sounds like you’re not technical so you might need someone to help build that page into your theme for you as you can’t just copy the above code to a new template file without knowing a bit of PHP.

    Thread Starter amministratore01pi

    (@amministratore01pi)

    Yes, actually I’m not an expert in wordpress and php. What solution could you give me then?

    graphicscove

    (@graphicscove)

    Sorry, I’m a technical developer. Perhaps you might be able to find a plugin that does similar to avoid having to code, but unfortunately I don’t know of any off the top of my head.

    Thread Starter amministratore01pi

    (@amministratore01pi)

    Ok, thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.