move_uploaded_file-无法打开流-没有此类文件或目录

时间:2020-06-27 14:41:29

标签: php html forms file-upload

这是我的表单代码:

<form method='POST' enctype="multipart/form-data">
   <input type='file' name='newPicture'>
   <button type='submit' name='submit' id='uploadPicBtn'>Upload Photo</button>
</form>

这是我的php代码:

<?php
    if (isset($_POST['submit'])) {
       if (isset($_FILES['newPicture'])) {
            $file = $_FILES['newPicture'];
            $serverpath = "images/".$file['name'];

            move_uploaded_file($file['tmp_name'], $serverpath);
       }
    }
?>

它们都在同一个.php文件(index.php)中。

我收到此错误: 警告:move_uploaded_file(images / anime.jpg):无法打开流:第7行的C:\ xampp \ htdocs \ account-settings \ index.php中没有此类文件或目录

警告:move_uploaded_file():无法在第7行的C:\ xampp \ htdocs \ account-settings \ index.php中将'C:\ xampp \ tmp \ phpB4E0.tmp'移动到'images / anime.jpg'

怎么了?

1 个答案:

答案 0 :(得分:-1)

使用:

$parent = dirname(__DIR__);
$serverpath = $parent."\\images\\".$file['name'];

代替:

$serverpath = "images/".$file['name'];

因为它在与php脚本相同的文件夹中搜索文件。 $ parent商店:C:\ xampp \ htdocs \(网站的根目录)