如何将上传的文件发送到我的数据库以及制作文件提交按钮?

问题描述 投票:0回答:0

我遇到的问题是我的代码行没有显示提交按钮,同时它也没有进入我设置的数据库。

`<?php
    /* 
     * 
     * 
     * Description: Upload Content Page
     */

    //Includes
    include 'connect.php'; //Connects to the DB
    
    //Check if the form was submittedƒ
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {

        $target_dir = "photo/";
$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"])) {
  $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  if($check !== false) {
    echo "File is an image - " . $check["mime"] . ".";
    $uploadOk = 1;
  } else {
    echo "File is not an image.";
    $uploadOk = 0;
  }
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
  echo "Sorry, your file is too large.";
  $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
  echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
  if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    echo "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded.";
  } else {
    echo "Sorry, there was an error uploading your file.";
  }
}
        
        if ($conn->query($sql) === TRUE) { //run the querry and check if it went through
            print "<strong>New Feedback added successfully</strong>";
        }else{
            print "Error: " . $sql . "<br>" . $conn->error;
        }
        
        $conn->close(); //Close the connection
        
        header('location:'.$_SERVER['PHP_SELF'].'?done'); //re-direct to success page (so they can't refresh)
    }
    
    if (isset($_GET['done'])) { //Show success message
        print "<strong>" .@$title. " added successfully</strong>"; //The @ sign causes the error to bypass the error log
    }
?>
<!DOCTYPE html>
<html>
<head>
</head>
 <p><a href="index.html">Home</a></p>
 <body>
 <form action="upload.php" method="post" enctype="multipart/form-data">
 Select image to upload:
 <input type="file" name="fileToUpload" id="fileToUpload'>
 <input type="submit" value="Upload Image" name="submit">
<form action="/action_page.php">
  <input type="file" id="myFile" name="filename">
  <input type="submit">
</form>
</form>

</body>
</html>`

我尝试了我在网上找到的东西,但没有帮助。我正在考虑启动将文件上传到数据库的过程的各种提交按钮。

php html css phpmyadmin
© www.soinside.com 2019 - 2024. All rights reserved.