Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Anyone know why this:

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

Gives:

Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in C:wampwwwupload.php on line 41
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:wampmpphp1AB.tmp' to 'c:wampwwwuploadsimages/' in C:wampwwwupload.php on line 41
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

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

it should be:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...