- Home /
 
How to download Image from mysql and convert to texture.
Hi everyone , I have been trying for a while to upload and download screenshots.
Basically here is what I have: The user click a button that calls a function in my C# code in unity that takes the screenshot and then send a form to this PHP code.
 <?PHP
 
 $name = $_POST['name'];
 
 
 /**********************   Image Test   **********************************/
 
 //$playerImage = $_POST['playerImage'];
 $tmpName = $_FILES['playerImage']['tmp_name'];            
 
 $fp      = fopen($tmpName, 'r');
 $content = fread($fp, filesize($tmpName));
 $content = addslashes($content);
 fclose($fp);
 
 /**********************   Image Test   **********************************/
 
 
 /**********************   Connect to Database   **********************************/
 
 $con = mysql_connect(-Hiden-) or ("Cannot connect!" .mysql_error());
 if (!$con) die('Could not connect: ' .mysql_error());
 
 mysql_select_db(-Hiden-,$con) or die ("could not load the database" .mysql_error());
 
 /**********************   Connect to Database   **********************************/
 
 
 /**********************   Update the Image in database   **********************************/
 
 $check = mysql_query("SELECT * FROM theDatabase WHERE name = '".$name."'");
 
 $numrows = mysql_num_rows($check);
 if($numrows == 0)
 {
     die("USERNAME NOT IN DATABASE SRY");
 }
 else
 {
         mysql_query("UPDATE theDatabase SET playerImage = '$content'  WHERE name = '".$name."'");
         die("saved");
 }
 
 /**********************   Update the Image in database   **********************************/
 
               Here is what I cannot achieve even after a good amount of time searching and trying. Download back the screenshot from the DB and use it as a texture.
I know for a fact that the upload part works without issues and I upload as PNG if it may help.
Here is one of my attemps in c#:
     void loadInfo()
     {        
         WWWForm form = new WWWForm();
         form.AddField("name",playerName);
         WWW w = new WWW("http://fakeLink.php",form);
         StartCoroutine(AttemptLoading(w));
     }
 
               but I fail to return the image as string. Here is the last thing I tried but it gives me errors as unity doesn't recognize it. (The end of my PHP Code . You dont need the rest of it anyway).
 $numrows = mysql_num_rows($check);
 if($numrows == 0)
 {
     die("USERNAME NOT IN DATABASE SRY");
 }
 else
 {
     echo $text;    
     echo ",";
         echo $text2;    
     echo ",";
         echo $text3; 
 
 // Note that the only issue in this script is echoing the playerImage.
         echo ",";
         echo "<img src= ".$playerImage" />";
 
         die(",");
 }
 
               Finally here is the error that Unity Spits out Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' ... and FormatException: Input string was not in the correct format
Please let me know if you can help me out!
Answer by $$anonymous$$ · May 30, 2018 at 09:20 PM
hello friend I have almost the same problem as you, I can receive data from my database but I want to show images and I can not, have you found the solution?
I would like you to show me how you did it if you could find it
Your answer