title: How to use an external php file to view images in xampp?
body: <p>So I am taking a web project from a web server and using it in XAMPP. In the original code, A user selects a file to upload. On submit the file is moved to the upload folder outside of the public html folder, and then the database is updated with the file name. I then use a select statement to get the file name from the database. Then I use a php include file to view the image within the img tag with the file name from the database. </p>
  
  <p>I made an upload folder in the project folder to store images(as if it were the upload folder in a web server), and changed the file paths respectively. </p>
  
  <p>So my problem is that the image does not show, everything else works up until I get to the image file that reads the image and I don't know why. I've tried to echo out the $image variable to see the path and it does not show either. So I think its the image file itself but can't be sure. Not sure where to go from here.</p>
  
  <p>Please read this carefully.</p>
  
  <p>File Structure:</p>
  
  <p><strong>projectfolder</strong></p>
  
  <p>-includes</p>
  
  <p>-pagelets</p>
  
  <p>-upload</p>
  
  <p>pagelet code:</p>
  
  <pre><code>&lt;?php
  //Upload Image
  if (isset($_POST['uploadImg'])) {
      if (is_uploaded_file($_FILES['image']['tmp_name'])) {
          if (move_uploaded_file($_FILES['image']['tmp_name'], "upload/{$_FILES['image']['name']}")) {
              echo "File Uploaded";
          }else{
              echo "File not uploaded";
              $i = '';
          }
          $i = $_FILES['image']['name'];
      }else{
          $i ='';
      }
  
      //Update database
      $query = "UPDATE Employees SET Photo = '$i' WHERE EmployeeID = {$_SESSION['EmpId']}";
      $result = @mysqli_query($dbc, $query);//Run the query
  }
  $query = "SELECT EmployeeID AS id, Photo AS photo, CONCAT(FirstName, ' ', LastName) AS name, PhoneNumber AS phone, Email AS email FROM Employees WHERE EmployeeID = '{$_SESSION['EmpId']}'";
  $infoResult = @mysqli_query($dbc, $query);//Run the query
  if($infoResult){
      while($row = mysqli_fetch_array($infoResult, MYSQLI_ASSOC)){
  ?&gt;
  &lt;div id="profile-pic"&gt;
          &lt;?php
              echo "&lt;img src=\"includes/view-image.inc.php?file={$row['photo']}\" alt=\"{$row['photo']}\" /&gt;";
          ?&gt;
          &lt;form name="uploadForm" action="&lt;?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?&gt;?pagelet=Dashboard" method="post" enctype="multipart/form-data"&gt;
              &lt;input type="file" name="image"&gt;
  
              &lt;input type="submit" name="uploadImg" value="submit"&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;?php
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Include file:</p>
  
  <pre><code>&lt;?php
  $path = "/upload/"; //directory outside public_html on the server
  $file = ($_GET['file']);
  $image = $path.$file;
  header("Content-Type: image/jpg");
  @readfile($image);
  ?&gt; 
  </code></pre>