0
X
Add Snippet To Project
New Project
Add To Existing Project
<?php
// Get the upload directory path
$upload_dir = wp_upload_dir();
$directory_path = $upload_dir['basedir'];
// Get the list of directories
$directories = glob($directory_path . '/*', GLOB_ONLYDIR);
// Check if the form is submitted
if (isset($_POST['submit'])) {
// Rest of the code...
// ...
}
?>
<!-- HTML Form -->
<form method="POST" enctype="multipart/form-data">
<label for="directory">Select a directory:</label>
<select name="directory" id="directory">
<?php foreach ($directories as $directory) : ?>
<option value="<?php echo basename($directory); ?>"><?php echo basename($directory); ?></option>
<?php endforeach; ?>
</select>
<br>
<label for="image">Select an image:</label>
<input type="file" name="image" id="image">
<br>
<input type="submit" name="submit" value="Upload">
</form>
Explanation:
Make sure to replace the existing code in the 'wp-plugin.php' file with the updated code provided above. This will list all the directories and allow the user to select one before uploading an image.