PHP code example of jvizcaya / uploadable

1. Go to this page and download the library: Download jvizcaya/uploadable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jvizcaya / uploadable example snippets


namespace App;

use Illuminate\Database\Eloquent\Model;
use Jvizcaya\Uploadable\UploadableTrait;

class Post extends Model
{
    use UploadableTrait;
    /**
     * Uploadable rules.
     *
     * @var array
     */
     protected $uploadable = [
       'image' => ['folder' => 'posts']
     ];
}

namespace App\Http\Controllers;

use App\Post;

class PostController extends Controller
{
    public function store(Request $request)
    {
        $post = new Post($request->all());
        $post->save();

        $post->storageFile($request->image);
    }
}

$post->storageFile($request->image, 'image');


  use UploadableTrait;
  /**
   * Uploadable rules.
   *
   * @var array
   */
   protected $uploadable = [
     'image' => [
         'folder' => 'posts',
         'name_column' => 'title'
       ]
   ];


 $post->storageFile($request->image, 'image', 'file name');
 

 $post->storageFile($request->image, 'image', 'file name', 'folder_name');
 


  use UploadableTrait;
  /**
   * Uploadable rules.
   *
   * @var array
   */
   protected $uploadable = [
     'image' => [
         'folder' => 'posts',
         'name_column' => 'title',
         'thumbnail' => ['folder' => 'posts/thumbnails', 'size' => [150, 100]],
        ]
   ];



  use UploadableTrait;  
  /**
   * Uploadable rules.
   *
   * @var array
   */    
   protected $uploadable = [
     'image' => [
         'folder' => 'posts',
         'name_column' => 'title',
         'thumbnail' => [
           ['folder' => 'posts/150', 'size' => [150, 100]],
           ['folder' => 'posts/400', 'size' => [400, 300]]
         ],
        ]
   ];



  use UploadableTrait;
  /**
   * Uploadable rules.
   *
   * @var array
   */
   protected $uploadable = [
      'image' => [
         'folder' => 'posts',
         'name_column' => 'title',
         'thumbnail' => [
           ['folder' => 'posts/150', 'size' => [150, 100]],
           ['folder' => 'posts/400', 'size' => [400, 300]]
         ],
         'disk' => 'public'
      ],
      'photo' => [
          'folder' => 'photos',
          'name_column' => 'title',
          'disk' => 'local'
      ]
   ];


$post->deleteAllFiles();

$post->deleteFile('photo');

$post->deleteFile('photo', 'photos');

$post->deleteAllFiles(true);

$post->deleteFile('photo', 'photos', true);

$post->moveFile('images');

$post->moveFile('images', 'image', 'posts');