php - copy() 函数的第二个参数不能是目录

标签 php

谁知道这是为什么:

<?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/');
}

给予:

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
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

最佳答案

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

应该是:

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

关于php - copy() 函数的第二个参数不能是目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2618418/

相关文章:

PHP 如何执行多个where 条件?

php - php中的数组到字符串转换错误

php - 在 mysql json 列中搜索

php - 通过 jQuery/Ajax 调用 PHP 页面

php - MySQL&PHP - 不可见数据?唔?

php - PHP 中的 DOM : Decoded entities and setting nodeValue

php - 使用分层对象结构时如何保持低内存

php - 我们可以通过 PHP 脚本配置 cron 作业的时间间隔吗?

java - 什么是更快的 flex 和 Java 或 flex 和 php?

php - jQuery Ajax 返回整个页面