解决WordPress中无法将上传的文件移动至wp-content/uploads

搭建lnmp环境,放一个wordpress建站系统

lnmp环境很快就搭建完成了,但是在放wordpress的时候出现了一些问题

最主要的问题:

1.第一个是wp-content/uploads没有权限创建,

     这个自己手动创建一下,给个777权限就好了。

2.无法将上传的文件移动至wp-content/uploads。

  这是个主要的问题,也是比较麻烦的问题,百度的答案都是千篇一律的设置777权限,不要中文用户名,

  没有一点用。

  在获得解决办法之前首先描述一下背景

  装lnmp环境的时候全部是使用root用户安装的,但是当我放程序的时候是新创建了一个morequ用户,程序全部放到这个用户下,然后用nginx代理。

  这就出现了权限问题。

  翻遍了百度,一点用都没有,最后用bing搜索得到了一个答案。

  原文地址:http://www.aspku.com/cms/wordpress/55720.html

按照他的方法改了之后,连http都过不去,直接500了,经过多番努力,最终得到答案。

  a)修改nginx.conf

    在这个文件的最开始,有个设置user的地方,修改为:

user  root root;
worker_processes  1;

      b)修改php-fpm.conf

   在这个文件里看到这么一句话:

  

; Include one or more files. If glob(3) exists, it is used to include a bunch of
; files from a glob(3) pattern. This directive can be used everywhere in the
; file.
include=/etc/php-fpm.d/*.conf

     可以进入这个文件夹看一下,其中有一个www.conf文件

  修改这个文件的:

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
;                 mode is set to 0666
;listen.owner = morequ
;listen.group = morequ
;listen.mode = 0666

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = morequ
; RPM: Keep a group allowed to write in log dir.
group = morequ

   将本来的www用户改为我当前的用户。

  结果成功。

  

 

转载于:https://www.cnblogs.com/lic309/p/4832871.html

ruoyi-vue的common/uploads接口可以用于文件上传。具体使用方法如下: 1. 在你的前端代码,调用该接口时需要传入三个参数:file、type、folder。其,file为要上传文件;type为上传文件的类型,可以是image、file、video、audio等;folder为文件上传后存放的目录。 2. 在后端代码,首先需要在application.yml配置文件上传路径。具体配置方式可以参考下面的示例: ``` # 文件路径 file: # 文件存储目录 store-dir: /data/ruoyi/uploadPath # 文件访问地址 access-path: /profile ``` 在上面的代码,store-dir为文件存储的目录,access-path为文件的访问地址。 3. 在后端代码,需要编写处理文件上传的控制器方法。具体代码可以参考下面的示例: ```java @PostMapping("/uploads") public AjaxResult uploadFile(@RequestParam("file") MultipartFile file, @RequestParam("type") String type, @RequestParam("folder") String folder) throws IOException { try { // 上传文件并返回文件的访问地址 String filePath = FileUploadUtils.upload(file, type, folder); return AjaxResult.success("上传成功", filePath); } catch (Exception e) { return AjaxResult.error("上传失败"); } } ``` 在上面的代码,我们通过调用FileUploadUtils.upload方法来实现文件上传,并返回文件的访问地址。其,MultipartFile是Spring框架提供的文件上传对象。FileUploadUtils.upload方法是ruoyi-common模块提供的文件上传工具类。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值