ใช้ Laravel-Glide กับโฟลเดอร์สาธารณะ/อัปโหลด

ฉันต้องการใช้ Glide สำหรับแหล่งที่มาของภาพทั้งหมดของฉัน

ตามคำแนะนำนี้ ฉันสามารถรับภาพที่ http://myweb.dev/img/test.jpg?w=200&filt=sepia

ป้อนคำอธิบายรูปภาพที่นี่

เส้นทาง:

Route::get('/img/{path}', 'ImageController@show')->where('path', '.*');

ตัวควบคุม:

namespace App\Http\Controllers;

use Illuminate\Contracts\Filesystem\Filesystem;
use League\Glide\Responses\LaravelResponseFactory;
use League\Glide\ServerFactory;

class ImageController extends Controller
{
    public function show(Filesystem $filesystem, $path)
    {
        $server = ServerFactory::create([
            'response' => new LaravelResponseFactory(app('request')),
            'source' => $filesystem->getDriver(),
            'cache' => $filesystem->getDriver(),
            'cache_path_prefix' => '.cache',
            'base_url' => 'img',
        ]);

        return $server->getImageResponse($path, request()->all());
    }
}

เนื่องจากรูปภาพทั้งหมดของฉันเป็นไดเร็กทอรี /public/uploads ฉันจึงเปลี่ยนดังต่อไปนี้

เส้นทาง:

Route::get('uploads/{path}', 'ImageController@show')->where('path', '.*');

คอนโทรลเลอร์

public function show(Filesystem $filesystem, $path)
{
    $server = ServerFactory::create([
        'response' => new LaravelResponseFactory(app('request')),
        'source' => public_path(),
        'cache' => public_path(),
        'cache_path_prefix' => '.cache',
        'base_url' => 'uploads',
    ]);

    return $server->getImageResponse($path, request()->all());
}

เมื่อฉันไปที่ http://myweb.dev/uploads/test.jpg?w=200&filt=sepia ฉันได้ภาพที่ไม่มีการเปลี่ยนแปลงใดๆ หรือไดเร็กทอรี .cache ใดๆ ถูกสร้างขึ้น

ฉันลอง base_path() และ /uploads เช่นกัน แต่ก็ไม่ได้ผลเช่นกัน ฉันใช้ไดเรกทอรีอัพโหลดสำหรับ elfinder

ฉันทำอะไรผิดที่นี่?

ป้อนคำอธิบายรูปภาพที่นี่


person shin    schedule 05.01.2017    source แหล่งที่มา


คำตอบ (1)


สิ่งนี้ได้ผล ฉันใส่รูปภาพไว้ในไดเร็กทอรี public/uploads

เส้นทาง

Route::get('/img/{path}', 'ImageController@show')->where('path', '.*');

คอนโทรลเลอร์

namespace App\Http\Controllers;

use Illuminate\Contracts\Filesystem\Filesystem;
use League\Glide\Responses\LaravelResponseFactory;
use League\Glide\ServerFactory;

class ImageController extends Controller
{
    public function show(Filesystem $filesystem, $path)
    {
        $server = ServerFactory::create([
            'response' => new LaravelResponseFactory(app('request')),
            'source' => public_path('uploads'),
            'cache' => public_path('uploads'),
            'cache_path_prefix' => '.cache',
            'base_url' => 'img',
        ]);

        return $server->getImageResponse($path, request()->all());
    }
}
person shin    schedule 07.01.2017