php - Profile picture only displays black box with an "X" inside -
i trying set profile page user can upload profile picture. problem having when status changed 1 0 image changes default profile image small black box "x" in it. else works fine. thought might css not. if can assist, appreciated. thank you.
profile.php:
<?php $id= $_get['id']; $sql = "select * user id='$id'"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { $sqlimg = "select * profileimg id='$id'"; $resultimg = mysqli_query($conn, $sqlimg); while ($rowimg = mysqli_fetch_assoc($resultimg)) { echo "<div class='userprofileimage'>"; if ($rowimg['status'] == 0 ) { echo "<img src='images/profile".$id.".jpg'>"; } else { echo "<img src='images/profile_default.jpg'>"; } echo "<p>".$row['first']."</p>"; echo "</div>"; } } } else { echo "there no users yet!"; }
uploadprofile.php:
<?php session_start(); include '../dbh.php'; $id = $_session['id']; $userid = $id; if (isset($_post['submit'])) { $file = $_files['file']; $filename = $_files['file']['name']; $filetmpname = $_files['file']['tmp_name']; $filesize = $_files['file']['size']; $fileerror = $_files['file']['error']; $filetype = $_files['file']['type']; $fileext = explode('.', $filename); $fileactualext = strtolower(end($fileext)); $allowed = array('jpg', 'jpeg', 'gif', 'png', 'mov', 'mpeg4', 'mp4', 'avi', 'wmv', 'mpegps', 'flv', '3gpp', 'webm'); if (in_array($fileactualext, $allowed)) { if ($fileerror === 0) { if ($filesize < 500000) { $filenamenew = "profile".$id.".".$fileactualext; $filedestination = '../uploads/'.$filenamenew; $sql = "update profileimg set status=0 id='$id'"; $result = mysqli_query($conn, $sql); move_uploaded_file($filetmpname, $filedestination); header("location: ../profile.php?id=$userid"); } else { echo "your file large"; } } else { echo "there error uploading file"; } } else { echo "you cannot upload files of type"; } } ?>
files being uploaded uploads line below
$filedestination = '../uploads/'.$filenamenew;
and img src is
echo "<img src='images/profile".$id.".jpg'>";
please update code.
edit: allowing multiple extensions uploaded , on profile.php single extension used load picture.
Comments
Post a Comment