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
Display All
Display All
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
- <?php
- include('class.ShowUploadcodePage.php'); // Include upload code Script page.
- ?>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, intial-scale=1.0"/>
- <title>Upload - Avatar</title>
- <style>
- html, body{background: #ececec; height: 100%; margin: 0; font-family: Arial;}
- .main{height: 100%; display: flex; justify-content: center;}
- .main .image-box{width:300px; margin-top: 30px;}
- .main h2{text-align: center; color: #4D4D4D;}
- .main .tb{width: 100%; height: 40px; margin-bottom: 5px; padding-left: 5px;}
- .main .file_input{margin-top: 10px; margin-bottom: 10px;}
- .main .btn{width: 100%; height: 40px; border: none; border-radius: 3px; background: #27a465; color: #f7f7f7;}
- .main .msg{color: red; text-align: center;}
- </style>
- </head>
- <body>
- <!-------------------Main Content------------------------------>
- <div class="container main" >
- <div class="image-box">
- <h2>Image Upload</h2>
- <form method="POST" name="upfrm" action="" enctype="multipart/form-data">
- <div>
- <input type="text" placeholder="Enter image name" name="img-name" class="tb" />
- <input type="file" name="fileImg" class="file_input" />
- <input type="submit" value="Upload" name="btn_upload" class="btn" />
- </div>
- </form>
- <div class="msg">
- </div>
- </div>
- </div>
- </body>
- </html>
PHP Source Code
- /*-- we included connection files--*/
- include "config.php";
- /*--- we created a variables to display the error message on design page ------*/
- $error = "";
- if (isset($_POST["btn_upload"]) == "Upload")
- {
- $uploadOk = 1;
- $file_tmp = $_FILES["fileImg"]["tmp_name"];
- $file_name = $_FILES["fileImg"]["name"];
- /*avatar name variable that you will insert in database ---*/
- $avatar_name = $_POST["img-name"];
- //avatar directory where actual avatar will be store
- $file_path = "photo/".$file_name;
- $target_file = $file_path . basename($file_name);
- /*---------------- php textbox validation checking ------------------*/
- if($avatar_name == "")
- {
- $error = "Please enter avatar name.";
- }
- /*-------- now insertion of avatar section has start -------------*/
- else
- {
- if(file_exists($file_path))
- {
- $error = "Sorry,The <b>".$file_name."</b> avatar already exist.";
- $uploadOk = 0;
- }
- else
- {
- $result = mysqli_connect($host, $uname, $pwd) or die("Connection error: ". mysqli_error());
- mysqli_select_db($result, $db_name) or die("Could not Connect to Database: ". mysqli_error());
- mysqli_query($result,"INSERT INTO avatar_table(img_name,img_path)
- VALUES('$avatar_name','$file_path')") or die ("avatar not inserted". mysqli_error());
- move_uploaded_file($file_tmp,$file_path);
- $error = "<p align=center>File ".$_FILES["fileImg"]["name"].""."<br />avatar saved into Table.";
- }
- }
- }
- ?>