Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在laravel上上传图像不';t在线工作:Laravel_Php_Laravel - Fatal编程技术网

Php 在laravel上上传图像不';t在线工作:Laravel

Php 在laravel上上传图像不';t在线工作:Laravel,php,laravel,Php,Laravel,该项目在本地主机上运行良好,但在实时共享服务器上存在问题 我已尝试将此代码添加到index.php中 我已尝试将此代码添加到公用文件夹中的新sym.php文件中 这些解决方案都不管用 以下是我的控制器代码片段: public function storeBrand(Request $request){ $this->validate($request, ['brand_name'=> 'required', 'bran

该项目在本地主机上运行良好,但在实时共享服务器上存在问题

  • 我已尝试将此代码添加到index.php中
  • 我已尝试将此代码添加到公用文件夹中的新sym.php文件中
  • 这些解决方案都不管用

    以下是我的控制器代码片段:

    
        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.');
    
    
    注意

    上载图像时,可以跟踪路径,但找不到图像,返回空图像


    感谢您的时间和帮助。

    我得到了解决方案:

    我在web.php路由文件中写下了以下代码:

    Route::get('/linkstorage',function(){$targetFolder=base_path()。/storage/app/public';$linkFolder=$_SERVER['DOCUMENT_ROOT']../storage';符号链接($targetFolder,$linkFolder);})

    之后,我导航到我的url/linkstorage
    成功了

    查看控制器中的代码,它似乎是正确的。可能错误在与此方法关联的Blade文件中的表单中。根据经验,我倾向于忘记写这篇文章,这可能会解决你的错误

    把这个写在表单标签上

    <form action="{{ insert the route here }}" method="POST" enctype="multipart/form-data">
       // insert form input fields here...
    </form>
    
    
    //在此处插入表单输入字段。。。
    
    这是否回答了您的问题?
    Route::get('/linkstorage', function () {
        Artisan::call('storage:link');
    });
    
    
    
        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.');
    
    
    <form action="{{ insert the route here }}" method="POST" enctype="multipart/form-data">
       // insert form input fields here...
    </form>