Hello everybody i’m trying display image from my website on 000webhost. On website is just my image nothing else but background around image is white not black like in google images and when i open image in other tap background is white like on google images but url is long garbage . When I try display image from Google images it works but when i try display image from website image turns to red questionmark. The website url doesn’t end with .jpg that will be propably the problem. Please do you have any ideas how to solve this problem?
Display in unity script:
testTexture = new Texture2D(2, 1);
WWW www = new WWW("https://xxxxxxxx.000webhostapp.com/xxxxxxxxxx.php");
yield return www;
testTexture = www.texture;
testSprite = Sprite.Create(testTexture, new Rect(0,0,testTexture.width,testTexture.height), Vector2.zero);
testImage.sprite = testSprite;
PHP script for display image on website:
$sql="SELECT * FROM images WHERE ID='1'";
$sth=$conn -> query($sql);
$result=mysqli_fetch_array($sth);
echo '<img src="data: image/jpeg;base64,'.base64_encode($result['Image']).'"/>';
Most free hosters have some sort of anti-bot protection implemented. Those usually return some kind of special “landing page” to new users which contain javascript which will redirect the user to the correct page and set a cookie for further visits. You may want to check what content is actually returned. It’s most likely a HTML page. You may be able to disable this protection, but many do not allow that.
Note that many free hosters do not allow to use their service as pure database. The terms of services of 000webhost states:
- You will not access 000WEBHOST.COM Content (as defined below) or User
Content through any technology or
means other than through this Site
itself, or as 000WEBHOST.COM may
designate.
So unless your game / application is build to WebGL and actually hosted on the site you probably violate the ToS. However i’m not a lawyer. If you get it to work it’s probably unlikely that they will actually notice. Though you should keep that in mind in case you want to go into production.
edit
I just reaslised that your PHP code does actually return HTML and not the image. You should just return the raw image data. something like:
echo $result['Image'];
I have another problem. Here is my goal: In unity i choose some number(int) then i send this number to php script in my website. PHP script choose and display image on website from database with ID equal number from unity and then unity script download and display image. I get this error on website: Notice: Undefined index. I think the problem is unity dont send id for some reason. When i tried insert to database with $_POST it worked. Please do you have any ideas?
Unity script:
IEnumerator DisplayImage()
{
WWWForm wwwForm = new WWWForm();
wwwForm.AddField("id",1);
WWW www1 = new WWW("https://xxxxxx.000webhostapp.com/xxxxxxxxx.php", wwwForm);
yield return www1;
testTexture = new Texture2D(2, 1);
www1 = new WWW("https://xxxxxx.000webhostapp.com/xxxxxxx.php");
yield return www1;
testTexture = www1.texture;
testSprite = Sprite.Create(testTexture, new Rect(0,0,testTexture.width,testTexture.height), Vector2.zero);
testImage.sprite = testSprite;
}
PHP script:
$id= $_POST['id'];
$sql="SELECT * FROM images WHERE ID='$id'";
$sth=$conn -> query($sql);
$result=mysqli_fetch_array($sth);
echo $result['Image'];