我正在为我们的员工创建一个在线区域,以便在WordPress中创建新帖子,与学生共享课程资源。我目前正在开发一个部分,学生可以通过该部分将文档上传到自定义帖子(前端表单),然后将这些上传内容存储在上传目录中。
目前,我已经将其上载到目录中,但我无法确定如何根据帖子ID创建新文件夹。
非常感谢您的任何想法。
include_once plugin_dir_path( __FILE__ ).\'upload.php\';
function assignment_uploads(){
global $post;
echo \'
<form method="post" enctype="multipart/form-data" action="">
<input type="file" name="file_upload">
<input type="hidden" name="lesson_id" value="\'. $post->ID.\'">
<input type="submit" name="upload_submitted">
</form>
\';
}
add_shortcode( \'student_submission_upload_form\', \'assignment_uploads\' );
// store post id in var
$lesson_id = $_POST[\'lesson_id\'];
function create_uploads_folder() {
$upload_dir = $uploadFolder[\'basedir\'];
$upload_dir = $upload_dir . \'/submissions/\'.$lesson_id;
if (! is_dir($upload_dir)) {
mkdir( $upload_dir, 0705 );
}
}
register_activation_hook( __FILE__, \'create_uploads_folder\' );
// Upload file
if(!move_uploaded_file($_FILES[\'file_upload\'][\'tmp_name\'], $uploadFolder[\'basedir\'] . \'/submissions/\' . $lesson_id . \'/\' . $_FILES[\'file_upload\'][\'name\'])){
die(\'Error uploading file - check destination is writeable\');
}