如何更改WordPress媒体上传目录

One thing I've always missed about the "old" way of web development was the simplicity of FTP. No deploy scripts, no fuss: simple drag and drop of files and the files are there. I've used FTP for assets on this blog for over a decade but I'm finally ready to be lazy enough to want to drag images into WordPress and use them as WordPress intended.

关于Web开发的“旧”方式,我一直想念的一件事是FTP的简单性。 无需部署脚本,无需大惊小怪:只需简单地拖放文件,文件就在那里。 我在这个博客上使用FTP作为资产已有十多年了,但是我终于准备好懒惰,想要将图像拖入WordPress并按WordPress的意图使用它们。

The problem is that I want the files to upload to custom directory, not the wp-content/uploads directory that WordPress defaults to. The following PHP snippet in the WordPress wp-config.php file allows you to change WordPress' default upload directory:

问题是我希望文件上传到自定义目录,而不是WordPress默认的wp-content/uploads目录。 WordPress wp-config.php文件中的以下PHP代码段可让您更改WordPress的默认上传目录:


require_once(ABSPATH.'wp-settings.php');
define('UPLOADS', 'my-demo');

Files uploaded within the WordPress / browser interface will be added in this custom directory. Note that WordPress will create the directory if not present, and will also automatically create and upload the file to a {year}/{month} directory within that custom directory.

在WordPress /浏览器界面中上传的文件将添加到此自定义目录中。 请注意,WordPress将创建目录(如果不存在),还将自动创建文件并将其上传到该自定义目录中的{year}/{month}目录。

I wish I had set this configuration years ago. Having to open a separate app and then write the custom HTML to insert this image has been an inconvenience for a long time!

我希望我在几年前设置了此配置。 很长时间以来,必须打开一个单独的应用程序,然后编写自定义HTML才能插入此图像,这给您带来了很大的不便!

翻译自: https://davidwalsh.name/wordpress-upload

你可能感兴趣的:(如何更改WordPress媒体上传目录)