Laravel图像(在商店图片上工作)

时间:2018-05-18 02:44:02

标签: php laravel laravel-5 image-uploading

我正在开发一个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;
}

2 个答案:

答案 0 :(得分:1)

在php.ini中

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

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

答案 1 :(得分:0)

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; 
            }     
    }
 }