gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 00:20:16 26 4
gpt4 key购买 nike

谁知道这是为什么:

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com