问题
Basically, i'm inspired by this question in building image manager feature for my blog in laravel. However, for unknown reason i keep hitting Resource Limit in the production server.
Here's my code:
//Migrations
public function up()
{
Schema::create('images', function(Blueprint $table){
$table->increments('id');
$table->string('name')->unique();
$table->string('description')->nullable();
$table->string('image_path')->unique();
$table->string('mime');
// $table->integer('width')->unsigned();
// $table->integer('height')->unsigned();
$table->integer('filesize')->unsigned();
$table->timestamps();
});
}
//Route
Route::get('images/{path}', [
'as' => 'images',
'uses' => 'Common\ImageController@respond'
]);
//Controller
protected function respond($name)
{
$path = storage_path('/app/images/') . $name;
if(!Storage::exists('/images/' . $name))
{
//if it did not exists in storage, just throw 404
return abort(404);
}
//assume image_path as unique
$image_entity = ImageEnt::where('image_path', '=', $name)->first();
if($image_entity != null)
{
if($image_entity->mime != null)
{
//200 = HTTP OK
return (new Response(Storage::get('/images/' . $name), 200))->header('Content-type', $image_entity->mime);
}
}
return Response()->download($path);
}
Server specification:
- Shared Hosting
- RAM 512 (max php memory also 512)
- PHP max execution time 30
回答1:
It could be your PHP config, images tend to be large in size and the default limit in PHP is 2MB. Try ini_set('upload_max_filesize', '10M');
来源:https://stackoverflow.com/questions/32107486/laravel-route-to-image-in-storage-got-resource-limit-exceeded-in-server-and-i