本文介绍了宅基地/流浪者拒绝图像处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了Homestead问题.我有一段代码可以很好地在在线开发服务器上运行,但是在无家可归的Homestead上却失败了.该代码段是一个用ajax执行的代码,我在其中上传图像,将其保存在temp目录中,然后将其发送回用户,然后由用户进行裁剪.为此,我有两个函数,tempUpload和tempCrop. tempCrop失败,触发它的大多数行如下:

$img = getimagesize($imgUrl);

$ imgUrl是输入,其中包含temp文件夹中图像的URL.签入流浪者,我发现这些图像具有-rwxrwxrwx 1流浪者流浪者属性.控制台中出现的错误是"SyntaxError:JSON.parse:JSON数据第1行第2列的意外字符".

同样,这在在线版本中非常有效,因此我想这可能是权限问题或某些环境设置.流浪汉中的temp文件夹的权限如下:drwxrwxrwx 1个流浪汉流浪汉

我已检入/app/storage/logs,但出现的错误是:

'getimagesize(http://nominate.app:8000/temp/2078ec37e959dd733930ad758854ce4cb5f175de.jpg): failed to open stream: Connection refused'

我真的不知道还要研究什么,特别是因为它在运行centOS的另一个开发环境中运行良好.

有什么想法吗?

非常感谢.

解决方案

答案是将路径而不是 url 放入getimagesize. >

基本上,就您的虚拟机而言,它在端口80上提供服务.Vagrant无缝地将此端口转发到主机的端口8000.当您调用getimagesize时,它首先尝试解析主机名(nominate.app). ,并且,如果成功,它将尝试在端口8000上发起与它的连接.我猜测nominate.app已配置为解析为127.0.0.1(虚拟机),实际上并没有在端口8000上进行监听. /p>

在HTTP上执行这些类型的操作是一个坏主意,因为这会减慢速度并可能生成同一图像的多个临时副本.您可以使用Laravel的路径助手来帮助您确定图像的本地路径(即getimagesize(public_path() . "/temp/" . $filename) ).

I am running into a problem with Homestead. I have a piece of code that works well on an online dev server, but fails in the vagrant Homestead one.The piece of code is an ajax executed one, where I upload an image, save it in a temp directory and send it back to the user, who then crops it. For this, I have two functions, tempUpload and tempCrop. It is failing in tempCrop, and most the line that triggers it is the following:

$img = getimagesize($imgUrl);

$imgUrl is an input with the url to an image in a temp folder. Checking in vagrant, I saw that these images have attributes -rwxrwxrwx 1 vagrant vagrant. The error appearing in the console is "SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data".

Again, this works perfect in an online version, so I guess it is either a permission problem or some environment setting. The permissions for the temp folder in vagrant are as following: drwxrwxrwx 1 vagrant vagrant

I have checked in /app/storage/logs, and the error I'm getting is:

'getimagesize(http://nominate.app:8000/temp/2078ec37e959dd733930ad758854ce4cb5f175de.jpg): failed to open stream: Connection refused'

I really don't know what else to look into, specially since it is working fine in another dev environment I have, running centOS.

Any ideas?

Thanks a lot.

解决方案

The answer would be to put the path rather than the url into getimagesize.

Basically, as far as your virtual machine knows, it's serving on port 80. Vagrant seamlessly forwards this port to the host machine's port 8000. When you call getimagesize, it first tries to resolve the hostname (nominate.app), and, if successful, it tries to initiate a connection to it on port 8000. I'm guessing that nominate.app is configured to resolve to 127.0.0.1 (the VM), which isn't actually listening on port 8000.

It's a bad idea to perform those sorts of operations over HTTP, since it'll slow things down and potentially generate multiple temporary copies of the same image. You can use Laravel's path helpers to help you determine the local path of the image (i.e. getimagesize(public_path() . "/temp/" . $filename)).

这篇关于宅基地/流浪者拒绝图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 20:41