php - upload directly to s3 from laravel -


i using laravel 5.1 on homestead developing locally. working on established laravel source code. changed filesystem config use s3. having issue making code upload directly s3, or upload s3 @ all. here current code:

<?php class imagehandler {  public static function uploadimage($image, $folder, $filename = '', $type = 'upload'){     return call_user_func ( config::get('site.media_upload_function'), array('image' => $image, 'folder' => $folder, 'filename' => $filename, 'type' => $type) ); }  public static function getimage($image, $size = ''){     $img = ''; // placeholder image      $image_url = config::get('site.uploads_dir') . 'images/';      if($size == ''){         $img = $image;     } else {          switch($size){             case 'large':                 $img = str_replace('.' . pathinfo($image, pathinfo_extension), '-large.' . pathinfo($image, pathinfo_extension), $image);                 break;             case 'medium':                 $img = str_replace('.' . pathinfo($image, pathinfo_extension), '-medium.' . pathinfo($image, pathinfo_extension), $image);                 break;             case 'small':                 $img = str_replace('.' . pathinfo($image, pathinfo_extension), '-small.' . pathinfo($image, pathinfo_extension), $image);                 break;             default:                 $img = $image;                 break;         }     }      return $image_url . $img;  }   public static function upload($args){      // lets these arguments , assign them!     $image = $args['image'];     $folder = $args['folder'];     $filename = $args['filename'];      $type = $args['type'];      // hey if folder want put them in images. let's give them month , year folder     if($folder == 'images'){         $month_year = date('fy').'/';     } else {         $month_year = '';     }      // check out! upload folder     $upload_folder = 'content/uploads/' . $folder . '/'.$month_year;       if ( @getimagesize($image) ){          // if folder doesn't exist create it.         if (!file_exists($upload_folder)) {             mkdir($upload_folder, 0777, true);         }          if($type =='upload'){              $filename =  $image->getclientoriginalname();              // if file exists give unique name             while (file_exists($upload_folder.$filename)) {                 $filename =  uniqid() . '-' . $filename;             }               $uploadsuccess = $image->move($upload_folder, $filename);              if(strpos($filename, '.gif') > 0){                 $new_filename = str_replace('.gif', '-animation.gif', $filename);                 copy($upload_folder . $filename, $upload_folder . $new_filename);             }          } else if($type = 'url'){              $file = file_get_contents($image);              if(strpos($image, '.gif') > 0){                 $extension = '-animation.gif';             } else {                 $extension = '.jpg';             }               $filename = $filename . $extension;              if (file_exists($upload_folder.$filename)) {                 $filename =  uniqid() . '-' . $filename . $extension;             }              if(strpos($image, '.gif') > 0){                 file_put_contents($upload_folder.$filename, $file);                 $filename = str_replace('-animation.gif', '.gif', $filename);             }              file_put_contents($upload_folder.$filename, $file);          }           $settings = setting::first();          $img = image::make($upload_folder . $filename);          if($folder == 'images'){             $img->resize(1280, null, function ($constraint) {                 $constraint->aspectratio();             });              image::make($upload_folder . $filename)->resize(960, null, function ($constraint) {                 $constraint->aspectratio();             })->save($upload_folder . pathinfo($filename, pathinfo_filename) . '-large.' . pathinfo($filename, pathinfo_extension));              image::make($upload_folder . $filename)->resize(640, null, function ($constraint) {                 $constraint->aspectratio();             })->save($upload_folder . pathinfo($filename, pathinfo_filename) . '-medium.' . pathinfo($filename, pathinfo_extension));              image::make($upload_folder . $filename)->resize(320, null, function ($constraint) {                 $constraint->aspectratio();             })->save($upload_folder . pathinfo($filename, pathinfo_filename) . '-small.' . pathinfo($filename, pathinfo_extension));          } else if($folder == 'avatars'){             $img->resize(300, null, function ($constraint) {                 $constraint->aspectratio();             });         }          $img->save($upload_folder . $filename);          return $month_year . $filename;      } else {         return false;     } } 

how edit code in order upload files directly s3 bucket?


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -