问题描述
我意识到这可能是不可能的...我一直在摸索,尝试不同的东西,没有什么,但我认为这可能值得一个职位,放弃之前...
I realize this may not be possible... I've been scouring around and trying out different things to no avail, but I thought it might merit a post before giving up...
我把一个使用three.js(webGL)的应用程序放在一起,我想给用户选择输入一个URL到网络上的任何图像,并使用它来纹理一个3D对象在网络应用程序。这将是没有问题,如果不是为整个跨域安全问题。
I'm putting together an app that uses three.js (webGL) and I would like to give the user the option to input a URL to any image on the web and use that to texture a 3D object in the web app. This would be no problem if not for the whole cross-domain security issue.
我知道应该为CORS批准的图像的一些工作, t完全理解这一点,我的印象是,这必须设置在主机的端(和我的用户需要能够从网络上的任何地方拉取图像,并以纹理使用)>>我试过这个: a href =https://hacks.mozilla.org/2011/11/using-cors-to-load-webgl-textures-from-cross-domain-images/ =nofollow> https:// hacks .mozilla.org / 2011/11 / using-cors-to-load-webgl-textures-from-cross-domain-images / ...但它没有工作(可能是因为我误解了构成CORS批准)
I know there are supposed to be some work arounds for CORS approved images, though I don't entirely understand this, it's my impression this has to be set on the host's end (and my users need to be able to pull an image from anywhere on the web and use it at as texture) >> I've tried this: https://hacks.mozilla.org/2011/11/using-cors-to-load-webgl-textures-from-cross-domain-images/ ...but it didn't work (probably due to my misunderstanding of what constitutes "CORS approved" )
我以为可能做某种类型的php代理可能工作?我试过这样: ...但似乎没有任何运气。 (它可能没有被写入工作与图像...我得到MIME类型错误...当我黑客攻击了一点设法摆脱的错误,但仍然没有运气)
I thought that maybe doing some kind of php proxy might work? I tried this: http://benalman.com/code/projects/php-simple-proxy/docs/files/ba-simple-proxy-php.html ...but also didn't seem to have any luck. (it may not have been written to work with images... I was getting MIME type errors... and when I hacked around a bit managed to get rid of the error... but still no luck)
...希望有人能帮助你!
...hope someone out there can help!
推荐答案
EUREKA! loox喜欢代理的方式,
这样做的诀窍:)
EUREKA!!! loox like proxy's the way to go,this did the trick :)
<?php
// PHP Proxy
// Responds to both HTTP GET and POST requests
//
// Author: Abdul Qabiz
// March 31st, 2006
//
// Get the url of to be proxied
// Is it a POST or a GET?
$url = ($_POST['url']) ? $_POST['url'] : $_GET['url'];
$headers = ($_POST['headers']) ? $_POST['headers'] : $_GET['headers'];
$mimeType =($_POST['mimeType']) ? $_POST['mimeType'] : $_GET['mimeType'];
//Start the Curl session
$session = curl_init($url);
// If it's a POST, put the POST data in the body
if ($_POST['url']) {
$postvars = '';
while ($element = current($_POST)) {
$postvars .= key($_POST).'='.$element.'&';
next($_POST);
}
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
}
// Don't return HTTP headers. Do return the contents of the call
curl_setopt($session, CURLOPT_HEADER, ($headers == "true") ? true : false);
curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);
//curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// Make the call
$response = curl_exec($session);
if ($mimeType != "")
{
// The web service returns XML. Set the Content-Type appropriately
header("Content-Type: ".$mimeType);
}
echo $response;
curl_close($session);
?>
这篇关于跨域图像for three.js(canvas / webGL),代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!