上传php文件时返回false

qco9c6ql  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(341)

我的问题是我试图上传一个带有php代码的文件,但是 move_uploaded_file() 函数返回false。我做错什么了?
我的php代码:

<?php
  header("Access-Control-Allow-Origin: *");
  header("Content-Type: multipart/form-data");
  header("Access-Control-Allow-Methods: POST");
  header("Access-Control-Max-Age: 3600");
  header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
  $destFile = "/root/mysite/upload_files/";

 if( $_FILES['avatar']['name'] != "" )
 {
    $tmpFilePath = $_FILES['avatar']['tmp_name'];
    $fileName = basename($_FILES["avatar"]["name"]);
    move_uploaded_file($tmpFilePath, $destFile . $fileName);
 }     
?>
mpbci0fu

mpbci0fu1#

试试下面这样的。

// Upload file
if(!move_uploaded_file($_FILES['avatar']['tmp_name'], '/root/mysite/upload_files/' . $_FILES['avatar']['name'])){
    die('Error uploading file - check destination is writeable.');
}

die('File uploaded successfully.');

相关问题