Javascript 如何在knockoutJs和php中使用拖放功能?

Javascript 如何在knockoutJs和php中使用拖放功能?,javascript,php,html,file-upload,knockout.js,Javascript,Php,Html,File Upload,Knockout.js,我花了几个小时试图理解敲除绑定的js文件。 你能帮我用php把它上传到我的sql服务器上吗 下图显示了拖放的布局。 当按下submit按钮上载照片时,此图标显示php代码: <?php function resizeImage($resourceType,$image_width,$image_height,$resizeWidth,$resizeHeight) { // $resizeWidth = 100; // $resizeHeight = 100;

我花了几个小时试图理解敲除绑定的js文件。 你能帮我用php把它上传到我的sql服务器上吗

下图显示了拖放的布局。

当按下submit按钮上载照片时,此图标显示php代码:

    <?php

function resizeImage($resourceType,$image_width,$image_height,$resizeWidth,$resizeHeight) {
    // $resizeWidth = 100;
    // $resizeHeight = 100;
    $imageLayer = imagecreatetruecolor($resizeWidth,$resizeHeight);
    imagecopyresampled($imageLayer,$resourceType,0,0,0,0,$resizeWidth,$resizeHeight, $image_width,$image_height);
    return $imageLayer;
}
  session_start();
  // *** Include the class

if (isset($_POST['submit'])) {

  $newFileName = $_POST['filename'];
  if (empty($_POST['filename'])) {
    $newFileName = "gallery";
  }else {
    $newFileName = strtolower(str_replace(" ", "-", $newFileName));
  }

  $imageTitle = $_POST['filetitle'];
  $imageDesc = $_POST['filedesc'];

  $file = $_FILES['file'];

  $fileName = $file["name"];
  $fileType = $file["type"];
  $fileTempName = $file["tmp_name"];
  $fileError = $file["error"];
  $fileSize = $file["size"];



  $fileExt = explode(".", $fileName);
  $fileActualExt = strtolower(end($fileExt));

  $allowed = array("jpg", "jpeg", "png");

  if (in_array($fileActualExt, $allowed)){
    if ($fileError === 0) {
      if ($fileSize < 2000000) {
        $imageFullName = $newFileName . "." . uniqid("", true) . "." . $fileActualExt;
        $fileDestination = "../img/gallery/" . $imageFullName;

        include_once "db_connection.php";

        $sql = "SELECT * FROM users;";
        $stmt = mysqli_stmt_init($conn);
        if (!mysqli_stmt_prepare($stmt, $sql)) {
          echo "SQL statement failed";
        }else{
          mysqli_stmt_execute($stmt);
          $result = mysqli_stmt_get_result($stmt);
          $rowCount = mysqli_num_rows($result);
          $setImageOrder = $rowCount + 1;


          $sql = "UPDATE users SET imgFullName =?, orderGallery=? WHERE userId =?;";
          if (!mysqli_stmt_prepare($stmt, $sql)) {
            echo "SQL statement failed";
          } else{

            // Image editing
              $new_width = 800;
              $new_height = 600;

              $sourceProperties = getimagesize($fileTempName);
              $uploadImageType = $sourceProperties[2];
              $sourceImageWidth = $sourceProperties[0];
              $sourceImageHeight = $sourceProperties[1];

            $session_id = $_SESSION['userId'];
            echo $fileDestination;
            mysqli_stmt_bind_param($stmt, 'sii', $imageFullName, $setImageOrder, $session_id);
            mysqli_stmt_execute($stmt);
            echo $fileDestination . "file destination";
            echo $fileTempName . "file temp name";

            switch ($uploadImageType) {
                case IMAGETYPE_JPEG:
                    $resourceType = imagecreatefromjpeg($fileTempName);
                    $imageLayer = resizeImage($resourceType,$sourceImageWidth,$sourceImageHeight,$new_width,$new_height);
                    imagejpeg($imageLayer,$fileDestination);
                    break;

                case IMAGETYPE_GIF:
                    $resourceType = imagecreatefromgif($fileTempName);
                    $imageLayer = resizeImage($resourceType,$sourceImageWidth,$sourceImageHeight,$new_width,$new_height);
                    imagegif($imageLayer,$fileDestination);
                    break;

                case IMAGETYPE_PNG:
                    $resourceType = imagecreatefrompng($fileTempName);
                    $imageLayer = resizeImage($resourceType,$sourceImageWidth,$sourceImageHeight,$new_width,$new_height);
                    imagepng($imageLayer,$fileDestination);
                    break;

                default:
                    $imageProcess = 0;
                    break;
            }

            if ($stmt->error) {
              echo "Failure!!! " . $stmt->error;
            } else {
            //  move_uploaded_file($fileTempName, $fileDestination);
            }

             header("Location: ../putaria.php?upload=success");
          }
        }
      }else {
        echo "File size is too big!";
        exit();
      }
    }else {
      echo "You had an error!";
      exit();
    }
  }else {
    echo "You need to upload a proper file type!";
    exit();
  }
}