PHP:无法将上载的文件从tmp移动到远程服务器上的指定文件夹?

PHP:无法将上载的文件从tmp移动到远程服务器上的指定文件夹?,php,Php,我正在尝试将图像上载到远程服务器。但它不能像在本地服务器上那样正常工作。我正在检查允许的最大文件大小,并将其修改为6MB,还检查了权限。这表明我可以上传图片。另一方面,我设置的目标目标是$targetPath=$\u SERVER['DOCUMENT\u ROOT']/blog/uploads/'.basename($fileName)。但是,当我运行代码时,末尾的if-else仍然反馈“no”,并且error.log显示 Warning: move_uploaded_file(): Unabl

我正在尝试将图像上载到远程服务器。但它不能像在本地服务器上那样正常工作。我正在检查允许的最大文件大小,并将其修改为6MB,还检查了权限。这表明我可以上传图片。另一方面,我设置的目标目标是
$targetPath=$\u SERVER['DOCUMENT\u ROOT']/blog/uploads/'.basename($fileName)。但是,当我运行代码时,末尾的if-else仍然反馈“no”,并且error.log显示

Warning: move_uploaded_file(): Unable to move 'F:\xammp\xxx\tmp\xxx.tmp' to 'uploads/' in F:\xammp\xammp\htdocs\xxx\main.php on line 47
处理上传文件和数据的PHP代码:

  <?php
      session_start();
      require_once('./conn.php');
      require_once('./utils.php');
    
      if(isset($_POST['submit_btn'])) {
        if(empty($_POST['title']) || empty($_POST['content']) || empty($_POST['category_id'])) {
          header("Location: ./create_post.php");
          die("please enter the information");
        }
        
        $user = getName($_SESSION['email']);
        $author = $user['name'];
        $title = $_POST['title'];
        $content = $_POST['content'];
        $categoryID = $_POST['category_id'];
        $file = $_FILES['fileToUpload'];
        $fileName = $_FILES['fileToUpload']['name'];
        $fileType = $_FILES['fileToUpload']['type'];
        $fileTmpname = $_FILES['fileToUpload']['tmp_name'];
        $fileError = $_FILES['fileToUpload']['error'];
        $fileSize = $_FILES['fileToUpload']['size'];
    
        // To split a string
        $fileExt = explode('.', $fileName);
        $fileActualExt = strtolower(end($fileExt));
        $allowFiletype = array('jpg', 'jpeg', 'png');
    
        // define the uploaded image name
        // $postImageName = time() . '_' .$fileName;
        $targetPath = $_SERVER['DOCUMENT_ROOT']. '/blog/uploads/' .basename($fileName);
    
        // Checks if a value exists in an array
        if(!in_array($fileActualExt, $allowFiletype)) {
          echo "You can not upload file of this type";
          exit();
        }
    
        // if($fileError !== 0) {
        //   echo "There was an error uploading your file";
        //   exit();
        // }
    
        if(move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $targetPath)) {
          // $sql = "INSERT into oscar_articles (author, title, content, image, category_id) VALUES (?, ?, ?, ?, ?)";
          // $stmt = $conn->prepare($sql);
          // $stmt->bind_param('sssss', $author, $title, $content, $postImageName, $categoryID);
          // $result = $stmt->execute();
          // if(!$result) {
          //   die('Fail to add new category');
          // } else {
          //   header("Location: ./home.php");
          // }
        } else {
          echo "no";
        };
      }
    ?>


检查目标目录是否存在,以及是否启用了目标目录的写入权限。可能存在两个问题1)权限2)文件路径。检查这两件事。确保您已将项目上载到远程服务器的公共目录。