【发布时间】:2021-05-25 06:52:04
【问题描述】:
该项目在我的本地主机上运行良好,但在实时共享服务器上出现问题。
- 我已尝试将此代码添加到我的 index.php 中
// set the public path to this directory
$app->bind('path.public', function() {
return __DIR__;
});
- 我已尝试将此代码添加到我的公共文件夹中的新 sym.php 文件中
<?php
$targetFolder = $_SERVER['DOCUMENT_ROOT'].'/storage/app/public';
$linkFolder = $_SERVER['DOCUMENT_ROOT'].'/public/storage';
symlink($targetFolder,$linkFolder);
echo 'Symlink process successfully completed';
?>
- 我尝试在我的 web.php 中添加它,然后运行 site/linkstorage
Route::get('/linkstorage', function () {
Artisan::call('storage:link');
});
这些解决方案都不起作用
这是我的控制器代码的 sn-p:
public function storeBrand(Request $request){
$this->validate($request, ['brand_name'=> 'required',
'brand_url'=> 'required',
'brand_image'=>'image|nullable|max:1999']);
if($request->hasFile('brand_image')){
//1 : get filename with ext
$fileNameWithExt = $request->file('brand_image')->getClientOriginalName();
//2 : get just file name
$fileName = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
//3 : get just extension
$extension = $request->file('brand_image')->getClientOriginalExtension();
//4 : file name to store
$fileNameToStore = $fileName.'_'.time().'.'.$extension;
//upload image
$path =$request->file('brand_image')->storeAs('public/BrandImages', $fileNameToStore);
}
else{
$fileNameToStore ='noimage.jpg';
}
$brand=new Brand();
$brand->brand_name =$request->input('brand_name');
$brand->brand_url =$request->input('brand_url');
$brand->brand_image =$fileNameToStore;
$brand->save();
return redirect('/create_brand')->with('status', 'The '.$brand->brand_name.' Brand has been saved successfully. Create another one.');
注意
上传图片时可以追踪路径,但是找不到图片,返回空图片。
感谢您的时间和帮助。
【问题讨论】: