copy()函数的第二个参数不能是目录 [英] The second argument to copy() function cannot be a directory

查看:94
本文介绍了copy()函数的第二个参数不能是目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道为什么:

<?PHP
$title = trim($_POST['title']);
$description = trim($_POST['description']);

// Array of allowed image file formats 
$allowedExtensions = array('jpeg', 'jpg', 'jfif', 'png', 'gif', 'bmp');

foreach ($_FILES as $file) {
  if ($file['tmp_name'] > '') {
    if (!in_array(end(explode(".",
            strtolower($file['name']))),
            $allowedExtensions)) {
      echo '<div class="error">Invalid file type.</div>';
    }
  }
}

if (strlen($title) < 3)
  echo '<div class="error">Too short title</div>';
else if (strlen($description) > 70)
  echo '<div class="error">Too long desccription.</div>';

else {
  move_uploaded_file($_FILES['userfile']['tmp_name'], 'c:\wamp\www\uploads\images/');
}

赠予:

警告:move_uploaded_file()[function.move-uploaded-file]:copy()函数的第二个参数不能是C:\ wamp \ www \ upload.php中第41行的目录
Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in C:\wamp\www\upload.php on line 41

警告:move_uploaded_file()[function.move-uploaded-file]:无法将C中的'C:\ wamp \ tmp \ php1AB.tmp'移至C:\ wamp \ www \ uploads \ images/第41行的\ wamp \ www \ upload.php
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\php1AB.tmp' to 'c:\wamp\www\uploads\images/' in C:\wamp\www\upload.php on line 41

推荐答案

这是因为您正在移动文件,并且认为您正在尝试将该文件重命名为第二个参数(在本例中为Director).

It's because you're moving a file and it thinks you're trying to rename that file to the second parameter (in this case a director).

应为:

move_uploaded_file($_FILES['userfile']['tmp_name'], 'c:/wamp/www/uploads/images/'.$file['name']);

这篇关于copy()函数的第二个参数不能是目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆