I wrote this code for you:
global $lesson_id;
$lesson_id = $_POST['lesson_id'];
function create_uploads_folder() {
global $lesson_id;
$upload_dir = wp_upload_dir();
$upload_dir = $upload_dir['basedir'];
$upload_dir = $upload_dir . '/submissions/'. $lesson_id;
if ( ! is_dir( $upload_dir ) ) {
wp_mkdir_p( $upload_dir );
}
}
register_activation_hook( __FILE__, 'create_uploads_folder' );
// Upload file
$uploadFolder = wp_upload_dir();
if ( ! move_uploaded_file($_FILES['file_upload']['tmp_name'], $uploadFolder['basedir'] . '/submissions/' . $lesson_id . "https://wordpress.stackexchange.com/" . $_FILES['file_upload']['name'])){
die('Error uploading file - check destination is writeable');
}
Related Posts:
- How to show all available images in WP’s media library when using the Polylang plugin?
- Saving Media – Which Hook is Fired?
- retrieve custom image sizes from media uploader javascript object
- Is it possible to allow zip files to be uploaded in WordPress?
- WordPress monthly upload directory owner set to root
- Set a maximum upload count for users on a specific user role
- Append button to WordPress Image Details modal
- How to set custom upload directory per user after moving content directory
- Importing WordPress Attachments Into Custom Directories In wp-content/uploads/
- add_image_size creating lots of images (of various sizes)
- This file type is not allowed. Please try another
- File Upload Permissions
- Setting the uploads directory
- Retrieving JSON data in ajax request from media uploader
- How to disable WordPress Media resize different size version?
- insert post & Upload post thumbnail from the front end using ajax
- how to add new .webm mime types
- how can i simple change upload folders to %year%/%month%/%day%?
- How can I save the original filename to the database?
- How to side load an image from a service
- Regenerate thumbnails unexpected resolution (96 x 96)
- How to host different file formats/types for a media attachment without creating multiple attachments?
- Can’t write pdf file to upload directory using FPDF
- Change default uploads file using wp Skeleton
- Change default from “Attachment post URL” to “File URL” in Add Media
- how to use media library [closed]
- Adding Adobe files to a wordpress site [closed]
- Unable to Upload Images on Local Windows Install
- What types of files can I upload with the WordPress Uploader?
- Replacing Images in Media Library
- Creating a feature to upload multiples images in the Theme Options?
- Copying uploaded images not working in wordpress
- Disabling direct access to images using .htaccess
- Restrict WordPress Media Library for a specific user role (users can only see/select own media)
- Manual filename while uploading attachments
- Convert (-) and (escape) signs to (_) when uploading files on wordpress media library automatically
- Make WordPress compress full size image?
- Move files from flat upload directory to organised by year / month
- Can’t manipulate media uploads
- Alternative or workaround for wp_insert_attachment
- How to limit the number of simultaneous media uploads?
- Custom media uploader not showing library
- Symbolic link for uploads in wordpress
- Upload iPhone video clips to blog via native WP app
- Process uploads with phpThumb before generating thumbnails
- Resize existing library images
- WP 4.3.1 new install on localhost missing php.ini [closed]
- Large image upload size (using timthumb.php
- How can I manage and limit disk usage for each author?
- How would I change the 10 MB limit to 5 GB in this script?
- When does WP resize an image file
- How can I modify the media upload form fields?
- More Fields & Media Upload
- How does wordpress handle media files?
- Upload Custom Mime Types in WordPress (SVG, WebP)
- “Sorry, this file type is not permitted for security reasons.”
- Can upload through FTP but not through WP uploader
- upload_max_size doesn’t change
- Upload and attach to a post multiple image files [closed]
- Changing titles in Uploader for “Posts”
- WordPress upload file action hook
- Back up uploads folder outside of wp-content?
- Batch upload to create posts each with one image, headline, and body text
- Control resizing of uploaded images
- How to add an upload image button (just like the one in the Custom Header) in the Theme Options I just created?
- protect files from downloading on other than my site
- WordPress File Upload Form Returning Null
- How to add CSV upload functionality on the edit page of a Custom Post Type
- WordPress changing media file name upon upload
- How to remove media by filename?
- Restrict Users to Only Edit Media Owned by Users in Their Role
- media_handle_upload() returns Specified file failed upload test
- How to upload a file and have it available on the post for download?
- WP media upload issues
- Increase .htaccess file upload without prompting error
- Images uploaded via Gutenberg image block are cropped
- WordPress upload folder stuck in 2017
- Media uploads error
- How to move UPLOADS folder in sub-domain which hosted in another server
- When upload to media it says an error occurred but the file is uploaded
- Add file upload with validation to custom form
- Some images not appearing after switching from AWS S3 back to local
- Uploading a file results in attachment post, but file is missing
- Why I am not able to upload media files?
- Featured image to grayscale with PHP imagefilter – which hook to use?
- Store uploads on an external server?
- Force relative path in media library for LAN deployment
- WordPress Media manager select file button, how to prevent hiding?
- Make thumbnail from uploaded image without plugin
- Making Site A Use Site B’s wp-content Folder
- Limit number of uploaded attachments of specific context
- Set featured link not showing
- WordPress upload folder on separate server
- increase maximum upload file
- How i can upload images to another folder?
- make default upload folder year/month/day wordpress without plugin [duplicate]
- Display Image Upload from Contact Form 7 on Redirect Page [closed]
- media_handle_sideload() fails
- How to upload and add images to the existing post from the front-end with admin approval which is posted by other user
- Create media folder upon post publish?