所以,我试图更改我的应用程序中已存在的文件的名称,但它会抛出错误"权限被拒绝"。存储文件的目录具有777权限,它位于pubic /目录上,文件的用户所有者是apache用户,但只有文件,我的用户是存储文件的Director的所有者。
此外,我已将用户更改为我的但仍然收到错误。
我已经搜索了解决方案但没有找到解决方案。
任何想法或帮助都将非常感激:)
以下是代码:
//控制器
//Here I get the data of file I want to update.
$act = Act::find($request->id);
//Here I get the last slug name of the file
$filename = $act->filename;
//Here I set the new name of the file
$act->name = $request->name;
//Here I set the new slug name for the file
$act->filename = str_slug($request->name);
//Here I validate if there is a new file to upload
if($request->hasFile('filename'))
{
//If true, I get the extension, delete the old file and save the new file with the new slug name.
$extension = $file->getClientOriginalExtension();
File::delete(public_path('documents/acts'), $filename.'.pdf');
$file->move(public_path('documents/acts'), str_slug($act->filename).'.'.$extension);
}
else
{
//If false, I just want to change the slug name of the old file to the new slug name **Here it throws the error**
File::move('documents/acts/'.$filename.'.pdf', 'documents/acts/'.$act->filename.'.pdf');
}
//And finally, here I save.
$act->save();
解决方案 只需取出重命名行中的public_path:)