avatar

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • im trying to implement avatars for users but i having alittle isses....lol.
      i have made new table in the uni1_users label avatar... it displays on the overview page and looks like it uoloads but i cant display it....any ideas??..thanks

      Smarty-Template

      1. <?php
      2. include('class.ShowUploadcodePage.php'); // Include upload code Script page.
      3. ?>
      4. <html>
      5. <head>
      6. <meta charset="utf-8">
      7. <meta name="viewport" content="width=device-width, intial-scale=1.0"/>
      8. <title>Upload - Avatar</title>
      9. <style>
      10. html, body{background: #ececec; height: 100%; margin: 0; font-family: Arial;}
      11. .main{height: 100%; display: flex; justify-content: center;}
      12. .main .image-box{width:300px; margin-top: 30px;}
      13. .main h2{text-align: center; color: #4D4D4D;}
      14. .main .tb{width: 100%; height: 40px; margin-bottom: 5px; padding-left: 5px;}
      15. .main .file_input{margin-top: 10px; margin-bottom: 10px;}
      16. .main .btn{width: 100%; height: 40px; border: none; border-radius: 3px; background: #27a465; color: #f7f7f7;}
      17. .main .msg{color: red; text-align: center;}
      18. </style>
      19. </head>
      20. <body>
      21. <!-------------------Main Content------------------------------>
      22. <div class="container main" >
      23. <div class="image-box">
      24. <h2>Image Upload</h2>
      25. <form method="POST" name="upfrm" action="" enctype="multipart/form-data">
      26. <div>
      27. <input type="text" placeholder="Enter image name" name="img-name" class="tb" />
      28. <input type="file" name="fileImg" class="file_input" />
      29. <input type="submit" value="Upload" name="btn_upload" class="btn" />
      30. </div>
      31. </form>
      32. <div class="msg">
      33. </div>
      34. </div>
      35. </div>
      36. </body>
      37. </html>
      Display All

      PHP Source Code

      1. /*-- we included connection files--*/
      2. include "config.php";
      3. /*--- we created a variables to display the error message on design page ------*/
      4. $error = "";
      5. if (isset($_POST["btn_upload"]) == "Upload")
      6. {
      7. $uploadOk = 1;
      8. $file_tmp = $_FILES["fileImg"]["tmp_name"];
      9. $file_name = $_FILES["fileImg"]["name"];
      10. /*avatar name variable that you will insert in database ---*/
      11. $avatar_name = $_POST["img-name"];
      12. //avatar directory where actual avatar will be store
      13. $file_path = "photo/".$file_name;
      14. $target_file = $file_path . basename($file_name);
      15. /*---------------- php textbox validation checking ------------------*/
      16. if($avatar_name == "")
      17. {
      18. $error = "Please enter avatar name.";
      19. }
      20. /*-------- now insertion of avatar section has start -------------*/
      21. else
      22. {
      23. if(file_exists($file_path))
      24. {
      25. $error = "Sorry,The <b>".$file_name."</b> avatar already exist.";
      26. $uploadOk = 0;
      27. }
      28. else
      29. {
      30. $result = mysqli_connect($host, $uname, $pwd) or die("Connection error: ". mysqli_error());
      31. mysqli_select_db($result, $db_name) or die("Could not Connect to Database: ". mysqli_error());
      32. mysqli_query($result,"INSERT INTO avatar_table(img_name,img_path)
      33. VALUES('$avatar_name','$file_path')") or die ("avatar not inserted". mysqli_error());
      34. move_uploaded_file($file_tmp,$file_path);
      35. $error = "<p align=center>File ".$_FILES["fileImg"]["name"].""."<br />avatar saved into Table.";
      36. }
      37. }
      38. }
      39. ?>
      Display All
    • so i guess the php class is in includes/pages/game ?
      and the tpl file in templates/game/?

      then it would be easier to use the common structure, if the page is called via game.php?page=uploadecode
      the template dont need a html and bodytag
      but should be set to popup if you want the page to be one.

      i write some more details when have time.
    • PHP Source Code

      1. <?php
      2. class ShowUserpicPage extends AbstractGamePage
      3. {
      4. public static $requireModule = 0;
      5. public function __construct()
      6. {
      7. parent::__construct();
      8. }
      9. public function show()
      10. {
      11. global $USER;
      12. $ausgabe = '';
      13. if (isset($_POST['submit']) && $_POST['submit']=="Senden") {
      14. $ausgabe .= 'Upload compelte:<br>';
      15. if (isset($_FILES['thefile']['tmp_name']) && strpos($_FILES['thefile']['type'], 'image') !== false) {
      16. $size=getimagesize($_FILES['thefile']['tmp_name']);
      17. if ($size[2] == 1
      18. || $size[2] == 2
      19. || $size[2] == 3
      20. || $size[2] == 4) {
      21. // weiter mit der Verarbeitung
      22. $ausgabe .= 'imagecheck: succsess<br>';
      23. $endung = $_FILES['thefile']['type'];
      24. $endung = str_replace("image/", "", $endung);
      25. if($endung == 'jpeg'){
      26. $endung='jpg';
      27. }
      28. $blafile = "userpic/" . $USER['id'] . ".".$endung;
      29. if (file_exists($blafile)) {
      30. unlink("userpic/" . $USER['id'] . ".".$endung);
      31. }
      32. if (!move_uploaded_file($_FILES['thefile']['tmp_name'], "userpic/" . $USER['id'] . ".".$endung)) {
      33. // error coping
      34. }
      35. $ausgabe .= 'imagewrite: succsess<br>';
      36. $derrand = rand(0,100);
      37. $ausgabe .= '<img src="userpic/'.$USER['id'].'.'.$endung .'?v=' . $derrand . '" style="width: 7vw;
      38. height: 7vw;"><br>';
      39. echo'<span style="color:green;">'.
      40. $ausgabe.'</span>';
      41. $db = Database::get();
      42. $db->update("UPDATE %%USERS%% SET
      43. user_image = :pfad
      44. WHERE id = ".$USER['id'].";",array(':pfad' => "userpic/".$USER['id'] .".". $endung."?v=" . $derrand));
      45. }
      46. } else {
      47. if (isset($_FILES['thefile']['tmp_name'])) {
      48. die("<span style='color:white;'>Dieses File ist kein gültiges Bild. ".$_FILES['thefile']['type'].$_FILES['thefile']['tmp_name'] ." </span>");
      49. } else {
      50. die("Kein File übertragen");
      51. // man muss hier nicht zwingenderweise abbrechen,
      52. // das File kann auch freiwillig übermittelt worden sein,
      53. // je nach Anforderung
      54. }
      55. // Das Formular wurde gesendet
      56. }
      57. } else {
      58. // Das Formular muss angezeigt werden
      59. echo'<img style="width:100px; height:100px;" src="' . $USER["user_image"] .'" style="width: 7vw;
      60. height: 7vw;"><br><br><form enctype="multipart/form-data" action="game.php?page=Userpic"
      61. method="post" style="color: white;">
      62. Dein Userbild auswählen:<br>
      63. <input type="hidden" name="max_file_size" value="100000">
      64. <input name="thefile" type="file"><br>
      65. Erlaubt sind Bilder bis 100KB und<br>
      66. einer Größe von max. 100 Pixel x 100Px <br>
      67. die Formate gif und jpg.
      68. <input type="submit" name="submit" value="Senden">
      69. </form>\'>';
      70. }
      71. }
      72. }
      Display All
      make a folder userpic and make it writeable
      make a file includes\pages\game\ShowUserpicPage.class.php and include the code from above.
      make a colum in uni1_users named user_image and it shall be varchar.

      this is rougth not a beauty, just to provide a fast answer with little time to.
      it may work or not, didnt test it in version 2.0

      wrote it long time ago.
    • i have done the work as per install i get an error

      Parse error: syntax error, unexpected 'output' (T_STRING), expecting variable (T_VARIABLE) or '$' in /home/darkhori/public_html/includes/pages/game/class.ShowUserpicPage.php on line 16


      $ output = '' ;
      if i put location still same fault
      $ output = '/userpic' ;
    • my apologies my htm editor auto corrected to english........is up loads but i get this error...sorry




      Fatal error: Call to undefined method Database::get() in /home/darkhori/public_html/includes/pages/game/class.ShowUserpicPage.php on line 54

      $db = Database::get();
    • change this:

      PHP Source Code

      1. $db = Database::get();
      2. $db->update("UPDATE %%USERS%% SET
      3. user_image = :pfad
      4. WHERE id = ".$USER['id'].";",array(':pfad' => "userpic/".$USER['id'] .".". $endung."?v=" . $derrand));

      to

      PHP Source Code

      1. $GLOBALS['DATABASE']->query("UPDATE ".USERS." SET user_image = \"userpic/".$USER['id'] .".". $endung."?v=" . $derrand . "\" WHERE id = ".$USER['id'].");
    • changed the above and i get this error

      Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in
      class.ShowUserpicPage.php on line 54