尝试上传图片资料时,为什么以下图片很奇怪

时间:2019-07-08 12:47:02

标签: php

Not Found 404 Error

我设法将图片上传到上传文件夹中,但是由于某些原因,出现以下 404错误。根据我的理解,它无法识别文件类型,并且我认为我的代码正确吗?

我认为通过执行个人资料图片,我需要两个文件,一个在我的标题或登录页面中,另一个在处理该页面...

这是我的一个文件中的代码:

<?php


include_once __DIR__.'/header2.php';
include_once __DIR__.'/includes/dbh.php';
$id = $_SESSION['u_id'];
$status = 0;

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', 'png', 'pdf');

  if (!in_array($fileActualExt, $allowed)) {
      echo "<meta http-equiv='refresh' content='0;url=header2.php?upload_form=error'>";
      exit();
  } else {
      if ($fileError === 1) {
          echo "<meta http-equiv='refresh' content='0;url=header2.php?upload_form=error'>";
        exit();
      } else {
         if ($fileSize > 500000) {
            echo "<meta http-equiv='refresh' content='0;url=header2.php?upload_form=filesizeerror'>";
        exit();
         } else {
            $fileNameNew = "profile".$id.".".$fileActualExt;
            $fileDestination = 'uploads/'.$fileNameNew;
            move_uploaded_file($fileTmpName, $fileDestination);

            $sql = "UPDATE profileimg
                    SET status = ?
                    WHERE userid = ?
                   ;";

             $stmt = mysqli_stmt_init($conn);
                              if(!mysqli_stmt_prepare($stmt, $sql)) {
                                 echo "SQL error";
                              } else {
                                mysqli_stmt_bind_param($stmt, "ii", $status, $id);
                                mysqli_stmt_execute($stmt);



           echo "<meta http-equiv='refresh' content='0;url=header2.php?upload_form=success'>";
      exit();
         }
      }
  }
}
}

And this is the code in my other file:

  $sql = "SELECT * FROM users WHERE user_uid = ?;";

$stmt = mysqli_stmt_init($conn);

if (!mysqli_stmt_prepare($stmt, $sql)) {
   echo 'SQL error';
   exit();
} else {
    mysqli_stmt_bind_param($stmt, "s", $_SESSION['u_uid']);
    mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);
    $resultCheck = mysqli_num_rows($result);

    if($resultCheck > 0) {
      while ($row = mysqli_fetch_assoc($result)) {
        $id = $row['user_id'];
        $one = 1;
        $sqlImg = "SELECT * FROM profileimg WHERE userid = ? limit 1;";

        $stmt = mysqli_stmt_init($conn);

        if (!mysqli_stmt_prepare($stmt, $sqlImg)) {
           echo 'SQL error';
           exit();
        } else {
            mysqli_stmt_bind_param($stmt, "i", $id);
            mysqli_stmt_execute($stmt);
            $resultImg = mysqli_stmt_get_result($stmt);

            while ($rowImg = mysqli_fetch_assoc($resultImg)) {

                  if ($rowImg['status'] == 0) {
                    $filename = "uploads/".$id."*";
                    $fileinfo = glob($filename);
                    $fileext = explode(".", $fileinfo[0]);
                    $fileactualext = $fileext[1];
                    echo "<img class='profile_picture' src='uploads/profile".$id.".".$fileactualext."?".mt_rand()."'>";
                  } else {
                    echo "<img class='default_picture' src='uploads/profiledefault.jpg'>";

                  }

                  echo '<div class="welcome">Welcome back '.$row['user_uid'].'!</div>';

              }
            }
            }


}

0 个答案:

没有答案