我正在为我的页面开发一个插件。 目标是从用户页面上传自定义配置文件图像。 现在我想以预定义的名称存储每个图像。 遗憾的是,我没有计划如何在文件上传期间使用WordPress函数 目前,当我上传例如名称为 现在我想用这种方式定义新名称: p>
但这不起作用,因为 wp_upload_bits() code>设置文件的自定义名称: p>
$ filename = $ _FILES ['file'] ['name'];
$ uploaded_bits = wp_upload_bits(
$ filename,
null,
file_get_contents($ _FILES ['file'] ['tmp_name'])
);
code> pre>
yolo.png code>的图片时,名称仍为
yolo .PNG 代码>。 p>
$ filename ='profile-image-'。 get_current_user_id();
code> pre>
$ _ FILES ['file'] ['name'] code>是 暂时保存在我的服务器上的文件,这是
yolo.png code>。 所以你知道我如何达到我的目标吗? p>
div>
I'm currently developing a plugin for my page. The goal is to upload a custom profile image from a user page. Now I want to store each image under a pre-defined name. Sadly I've no plan how I can set a custom name for a file during the file upload with the WordPress function wp_upload_bits()
:
$filename = $_FILES['file']['name'];
$uploaded_bits = wp_upload_bits(
$filename,
null,
file_get_contents( $_FILES['file']['tmp_name'] )
);
Currently when I upload for example an image with the name yolo.png
, the name stays yolo.png
.
Now I want to define the new name this way:
$filename = 'profile-image-' . get_current_user_id();
But this can't work because the $_FILES['file']['name']
is the temporarily saved file on my server and this is yolo.png
. So do you have any idea how I can reach my goal?