我已经排好队了,它可以从给定的URL中保存图像(从远程获取图像并保存在本地),并且一切正常,但是,如果我将此代码放入已排队的工作中,则会出现错误。
local.ERROR:无法从给定的URL(存在的URL,我可以通过浏览器访问)初始化......
我可以访问这些URL,已启用allow_url_fopen
,并且此代码无需排队就可以工作。
try {
$img = Image::make($photo->url);
$img->save($path.$filenameBig); // Save the big image
} catch (NotReadableException $e) {
var_dump($e->getMessage());
}
这个$photo->url
是http
,我可以在错误中看到它(它不为空或什么)。我可以使用浏览器访问实际图像。我正在这样导入Image
:
在config/app
中使用别名:
'Image' => Intervention\Image\ImageManagerStatic::class,
在提供程序中(相同的文件):
Intervention\Image\ImageServiceProvider::class
然后使用它:
use Image;
Stacktrace
ErrorException: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/myes8adq/app/Libraries/PropertyLibrary.php:156
Stack trace:
0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions-handleError(2, 'file_get_conten...', '/home/myes8adq/...', 156, Array)
#1 /home/myes8adq/app/Libraries/PropertyLibrary.php(156): file_get_contents('https://dummyim...')
#2 /home/myes8adq/app/Libraries/PropertyLibrary.php(30): App\Libraries\PropertyLibrary->importOneChanged(Object(stdClass))
#3 /home/myes8adq/app/Jobs/ImportPropertiesAndNomenclaturesJob.php(48): App\Libraries\PropertyLibrary->importAllChanged()
#4 [internal function]: App\Jobs\ImportPropertiesAndNomenclaturesJob->handle()
#5 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#6 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#7 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#8 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Container/Container.php(576): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#9 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#10 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(App\Jobs\ImportPropertiesAndNomenclaturesJob))
#11 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(App\Jobs\ImportPropertiesAndNomenclaturesJob))
#12 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#13 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(49): Illuminate\Bus\Dispatcher->dispatchNow(Object(App\Jobs\ImportPropertiesAndNomenclaturesJob), false)
#14 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(88): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\RedisJob), Array)
#15 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(327): Illuminate\Queue\Jobs\Job->fire()
#16 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(277): Illuminate\Queue\Worker->process('redis', Object(Illuminate\Queue\Jobs\RedisJob), Object(Illuminate\Queue\WorkerOptions))
#17 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(230): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\RedisJob), 'redis', Object(Illuminate\Queue\WorkerOptions))
#18 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(102): Illuminate\Queue\Worker->runNextJob('redis', 'default', Object(Illuminate\Queue\WorkerOptions))
#19 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(86): Illuminate\Queue\Console\WorkCommand->runWorker('redis', 'default')
#20 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#21 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#22 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#23 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#24 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Container/Container.php(576): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#25 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\Container\Container->call(Array)
#26 /home/myes8adq/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#27 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#28 /home/myes8adq/vendor/symfony/console/Application.php(917): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#29 /home/myes8adq/vendor/symfony/console/Application.php(269): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#30 /home/myes8adq/vendor/symfony/console/Application.php(145): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#31 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Console/Application.php(90): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#32 /home/myes8adq/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(133): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#33 /home/myes8adq/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 {main}
答案 0 :(得分:1)
使用allow_url_fopen = On
运行主管{
"name": "superapp",
"version": "0.0.1",
"description": "",
"main": "server.js",
"scripts": {
"start": "node server"
},
"keywords": [],
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"dotenv": "^8.0.0",
"express": "^4.17.1"
}
}
答案 1 :(得分:1)
如果您位于共享主机上,而队列工作人员无法allow_url_fopen
,则可以通过cURL或GuzzleHTTP在本地下载图像,然后在本地文件上使用Image::make()
。
例如
$url = "http://www.example.com/img.jpg";
if (!ini_get('allow_url_fopen') && function_exists('curl_version')) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($curl);
curl_close($curl);
} else if (ini_get('allow_url_fopen')) {
$content = file_get_contents($url);
} else {
echo 'No dice.';
}
$i= Image::make($content);