php:move_uploaded_file()无法移动图像

时间:2019-04-28 20:51:57

标签: php post

我是上传文件的新手,我的处理程序无法正常工作。我猜应该归咎于临时文件处理。有人可以在下面看到我在做什么错吗?我的图片文件夹(与当前文件位于同一文件夹中)没有收到上传的图片。

function uploadImage() {

  var_dump($_FILES);
  echo <<<'EOD'
  =====$_FILES=====
EOD;

/*
array (size=1)
  'imageCoupon' => 
    array (size=5)
      'name' => string 'diet.jpg' (length=8)
      'type' => string 'image/jpeg' (length=10)
      'tmp_name' => string '/tmp/phpBlfzEy' (length=14)
      'error' => int 0
      'size' => int 53196
 * /  


  $fileName = $_FILES['imageCoupon']['name'];
  $fileContents = $_FILES['imageCoupon']['tmp_name'];

  var_dump($fileContents); // '/tmp/phpfTgBev' (length=14)
  echo <<<'EOD'
  =====$fileContents=====
EOD;

  var_dump($fileName); // 'diet.jpg' (length=8)
  echo <<<'EOD'
  =====$fileName=====
EOD;

  $destination = __FILE__ . 'images/' . $fileName;

  var_dump($destination); // '/var/www/html/wptest2/wp-content/plugins/frequentVisitorCoupons/frequentVisitorCoupons.phpimages/diet.jpg' (length=105)
  echo <<<'EOD'
  =====$destination=====
EOD;

  // take the file named in the POST request and move it to './images'
  move_uploaded_file($fileContents, $destination);
};

0 个答案:

没有答案