如何将文件移动到cpanel文件夹中

时间:2019-07-05 15:47:44

标签: php

我还有其他一些线程,但是仍然无法弄清楚为什么我不能使用以下代码将文件移入文件夹?我还想知道是否存在任何安全问题,例如人们在文件中放置病毒,Windows Defender是否足以阻止这种情况发生?

<?php
if (isset($_POST['submit'])) {
  $file = $_FILES['file'];
  $fileName = $_FILES['file']['name'];
  $fileTmpName= $_FILES['file']['tpm_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)) {
      header("Location: upload.php?upload_form=typeerror");
        exit();
  } else {
      if ($fileError === 1) {
          header("Location: upload.php?upload_form=error");
        exit();
      } else {
         if ($fileSize > 500000) {
             header("Location: header2.php?upload_form=filesizeerror");
        exit();
         } else {
            $fileNameNew = uniqid('', true).".".$fileActualExt;
            $fileDestination = 'uploads/'.$fileNameNew;
            move_uploaded_file($fileTmpName, $fileDestination);
             header("Location: header2.php?uploadform=success");
        exit();
         }
      }
  }
}

enter image description here

1 个答案:

答案 0 :(得分:0)

您在tmp_name中输入错误

更改此行

$fileTmpName= $_FILES['file']['tpm_name'];

$fileTmpName= $_FILES['file']['tmp_name'];

这将解决您的问题。