Click here to Skip to main content
15,442,578 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
heres the code im having problems with
<?php 
           if (!isset($_SESSION['username'])) {
           $pfp_source = '/uploads/' ['fileToUpload'];
           }
            ?>
           <img id="profile-img" src="<?php "$pfp_source" ?>" style="width: 50%; float: left;">
           <h5 id="name"><?php echo $username ?></h5>


i use
<?php require('../Account/upload.php') ?>


and upload php is this
<?php include('server.php') ?>

  <?php
  session_start();
    if (!isset($_SESSION['username'])) {
    $_SESSION['msg'] = "You must log in first";
    header('location: Login.php');
  }

  $username = $_SESSION['username'];
  ?>

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

        <div class="navbar5">
    <a class='btn5' href="../main.php">Main</a>
    <a class='btn5' href="../Credits/">Credits</a>
    <a class='btn5' href="../Chat/">Chat</a>
    <a class='btn5' href="index.php">Profile</a>

  </div>
  <div id="content">
  
<form action="upload.php" method="post" class="form-act" enctype="multipart/form-data">
  <style type="text/css">
    color:white ;
  </style>
    <input type="file" class="fileToUpload" name='fileToUpload'>
    <br/>
    <input type="submit" value="upload" class="submit-image" name="submit-image">
  </form>

      </body>
    </html>

     <?php
$target_dir = "../Chat/uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

// Check if image file is a actual image or fake image
if(isset($_POST["submit-image"])) {
  $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  if($check !== false) {
    echo "";
    $uploadOk = 1;
  } else {
    echo "";
    $uploadOk = 0;
  }
}

// Check if file already exists
if (file_exists($target_file)) {
  echo "";
  $uploadOk = 0;
}

// Check file size
if ($_FILES["fileToUpload"]["size"] > 1000000) {
  echo "ur file is too large";
  $uploadOk = 0;
}

// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") {
  echo "";
  $uploadOk = 0;
}

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
  echo "";
// if everything is ok, try to upload file
} else {
  if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    echo "The file ". htmlspecialchars( basename("image has been uploaded."));
  } else {
    echo "";
  }
}
?>

so um in the index.php im having a problem in this place
<?php
         if (!isset($_SESSION['username'])) {
         $pfp_source = '/uploads/' ['fileToUpload'];
         }
          ?>
         <img id="profile-img" src="<?php "$pfp_source" ?>" style="width: 50%; float: left;">
         <h5 id="name"><?php echo $username ?></h5>
because it says that the image source is (unknown) its empty for some reason idk why
<img id="profile-img" src="" style="width: 50%; float: left;">
that is what i see when going to the page i hope yall understand what i mean, i can upload full code of index.php and upload.php if needed

What I have tried:

i asked help from my friend but he didnt know and then i tried other stuff like changing the code to
<?php 
           if (!isset($_SESSION['username'])) {
           $pfp_source = '/uploads/' ['tmp_name'];
           }
            ?>
           <img id="profile-img" src=<?php echo '"'.$pfp_source.'"' ?> style="width: 50%; float: left;">
           <h5 id="name"><?php echo $username ?></h5>
in the chat aka index.php but didnt work it gave me the same result "(unknown)"
Posted
Updated 6-Feb-22 3:21am

1 solution

The same issue as in your other question, the names you are using are not valid.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900