我有自定义上传功能,可以在我的WordPress上传文件。
我的自定义模板upload_page.php
if ( isset($_FILES['test_upload']) ) {
$a = $_FILES['test_upload'];
$arr = array();
foreach ($_FILES['test_upload'] as $key => $value) {
foreach ($value as $k => $v) {
$arr[$k][$key] = $a[$key][$k];
}
}
foreach ($arr as $key => $file) {
upload_user_file($file);
}
}
这是我上传文件的html表单:
<form id="" class="" action="" method="POST" enctype="multipart/form-data">
<input type="file" name="test_upload[]" id="test_upload" accept=".pdf" multiple />
<input onclick="move()" type="submit" />
</form>
这是我的功能:
if(isset($file_return['error']) || isset($file_return['upload_error_handler'])){
return false;
}else{
$filename = $file_return['file'];
$attachment = array(
'post_mime_type' => $file_return['type'],
'post_content' => '',
'post_type' => 'attachment',
'post_status' => 'inherit',
'guid' => $file_return['url']
);
我需要在上传文件的名称中加上已上传的用户名。
答案 0 :(得分:0)
在您的功能&#39; upload_user_file &#39; :
修改强>
$user = wp_get_current_user();
$username = $user->user_login;
$filename = $file_return['file'] . $username;
答案 1 :(得分:0)