【问题标题】:Laravel Image ( Working on store image )Laravel 图片(处理商店图片)
【发布时间】:2018-10-28 09:46:59
【问题描述】:

我正在开发一个 laravel 商店图像功能。幸运的是它正在工作。但我的问题是当我尝试上传至少 20 多张图片时。它只存储前 20 张图像。

我的问题是,是否有任何设置限制我的代码上传 20 多个文件?

这是我的代码

public function storeImages($keycode, $projectsID){
    if(!empty($_FILES[$keycode]['name']) && isset($_FILES[$keycode]) && is_array($_FILES[$keycode]['name'])):
        for($i = 0; $i < count($_FILES[$keycode]['name']); $i++):
            $filename = preg_replace("/[^a-z0-9A-Z\.]/","_",$_FILES[$keycode]['name'][$i]);
            move_uploaded_file($_FILES[$keycode]['tmp_name'][$i],"uploads/projects/".$filename); //stores original size
            try{
                if(trim($filename) != ""){
                    $img = \Image::make("uploads/projects/".$filename); //opens the original sizes
                    $img->resize(200,200); // resize original
                    $img->save('uploads/projects/200x200_'.$filename); // save resize images
                    $new = array();
                    $new['id'] = \App\Helper\ModelHelper::uuid();
                    $new['project_id'] = $projectsID;
                    $new['type'] = "BEFORE";
                    $new['img_name'] = $filename;
                    DB::table("projects_photos")->insert($new);
                }
            }catch(Exception $e){

            }
        endfor;
    endif;
}

【问题讨论】:

    标签: php laravel laravel-5 image-uploading


    【解决方案1】:

    在 php.ini 中

    ; Maximum number of files that can be uploaded via a single request
    max_file_uploads = 20
    

    更改此项并重新启动 apache/nginx 服务器

    【讨论】:

    • 对不起,我很笨。我刚刚看到我的inifile配置使用phpinfo(),上面写着max_file_uploads20。我的问题。在我的 laravel 项目中哪里可以找到 php.ini
    • 在 phpinfo() 结果中,有 Loaded Configuration File 。在这个指定的 php.ini 路径中
    • 谢谢你刚刚修复它。
    【解决方案2】:

    public static function Uploaduserimage($input=array(),$request){
    
    if ($request->hasFile('userimg') && $request->file('userimg')->isValid()){ 
              $image = $request->file('userimg');
               $image_ext =  $image->getClientOriginalExtension();
               $imagetxt= array('gif','png','bmp','jpeg','jpg');
                if(!in_array( $image_ext,$imagetxt)){ 
                    return false;  
                }
                else{ 
                    $folderPath =  base_path()."/public/your image path"; 
                    if(!is_dir($folderPath))  {
                        mkdir($folderPath,0777,true);
                        chmod($folderPath,0777);
                        $folderPath = $folderPath;
                    } else {
                        $folderPath = $folderPath;
                    }
                    $image_Path=$folderPath;
                    $newimg_name = substr(mt_rand(),0,5).time().".".$image_ext; 
                    $request->file('userimg')->move($image_Path, $newimg_name);
    
                    if(!empty($newimg_name))
                    $obj->image=$newimg_name; 
                    if($obj->save()){
                        return true;}
                     else 
                         return false; 
                }     
        }
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-05
      • 1970-01-01
      • 2017-08-13
      • 2015-12-19
      • 1970-01-01
      • 2018-09-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多