好的,所以我在一个使用cpanel的共享主机上托管了一个Laravel(版本5.4)网站。我管理的public_html不在应用程序的根目录中。现在当我的应用尝试通过我的管理面板将图像上传到服务器时出现问题。因此,我上传的每张图片都有权限600,因此他们以后无法使用它们(当我需要稍后在图库中显示它们时)。现在,我可以手动更改权限,但它不会保留我的蜡烛,因为显然应用程序中的某些内容被破坏并使图像具有600个权限。
这是我的存储图像控制器
class GuitsController extends Controller{
public function store(Request $request){
$this->validate($request, [
'tbNaziv' => 'required|alpha',
'tbMarka' => 'required|alpha',
'tbTip' => 'required|alpha',
'tbOpis' => 'required|alpha',
'tbCena' => 'required|alpha_num',
'tbSlika' => 'required|mimes:jpg,jpeg,png,gif'
]);
$naziv = $request->get('tbNaziv');
$marka = $request->get('tbMarka');
$tip = $request->get('tbTip');
$opis = $request->get('tbOpis');
$cena = $request->get('tbCena');
$pic = $request->file('tbSlika');
$temp_path = $pic->getPathname();
$ext = $pic->getClientOriginalExtension();
$picName = time() . '.' . $ext;
$path = 'pics/guits/' . $picName;
$server_path = public_path($path);
try{
File::move($temp_path, $server_path);
$guit = new Guit();
$guit->naziv = $naziv;
$guit->marka = $marka;
$guit->tip = $tip;
$guit->opis = $opis;
$guit->cena = $cena;
$guit->putanja_slike = $path;
$result = $guit->save();
if($result == 1){
return redirect()->route('home')->with('success', 'Uspesan unos');}
else{
return redirect()->route('home')->with('error', 'Neuspesan unos');}
}
catch (\Exception $exception){
\Log::error('Greska: ' . $exception->getMessage());
}
}}
以下是我在AppServiceProvider.php中所做的工作,以使public_path工作
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{ $this->app->bind('path.public', function() {
return realpath(base_path().'/../public_html');
});
}
}
显然,应用中的某些内容使上传的图片具有权限600 ... 有人有任何想法吗?