PHP没有这样的文件或目录错误

时间:2018-03-22 02:57:49

标签: php nosuchfileexception

  

警告:move_uploaded_file(C:\ mpp \ htdocs \ ch09 \ data2018_03_22_11_38_23_0.gif):无法打开流:第101行的C:\ xampp \ htdocs \ ch09 \ concert \ insert.php中没有此类文件或目录< / p>      

警告:move_uploaded_file():无法在C:\ xampp \ htdocs \ ch09 \ concert中将'C:\ xampp \ tmp \ phpE1D0.tmp'移动到'C:\ mpp \ htdocs \ ch09 \ data2018_03_22_11_38_23_if.gif' 101号线上的\ insert.php

$upload_dir = "C:\xampp\htdocs\ch09\data";

我认为file_name设置正确,但uploaded_dir不是。

尽管输入正确,但仍错过了

\xa。为什么呢?

<?php session_start(); ?>

<meta charset="utf-8">
<?php

    $userid = $_SESSION["userid"];
    if(isset($_REQUEST["page"]))
    {
        $page = $_REQUEST["page"];
    }else{
        $page = 1;
    }

if(!$userid) {
    echo("
    <script>
     window.alert('로그인 후 이용해 주세요.')
     history.go(-1)
   </script>
    ");
    exit;
}

    if(isset($_REQUEST["mode"])){
        $mode = $_REQUEST["mode"];
    }else{
        $mode ="";
    }

    if(isset($_REQUEST["num"])){
        $num = $_REQUEST["num"];
    }else{
        $num = "";
    }

    if(isset($_REQUEST["html_ok"])) //checkbox는 체크해야 변수명 전달됨
        $html_ok = $_REQUEST["html_ok"];
    else
        $html_ok = "";

    $subject = $_REQUEST["subject"];
    $content = $_REQUEST["content"];


        // 다중 파일 업로드
$files = $_FILES["upfile"];
$count = count($files["name"]);
    $upload_dir = "C:\xampp\htdocs\ch09\data\\";

$regist_day = date("Y-m-d (H:i)");  // 현재의 '년-월-일-시-분'을 저장
    /*   단일 파일 업로드 
    $upfile_name     = $_FILES["upfile"]["name"];
    $upfile_tmp_name = $_FILES["upfile"]["tmp_name"];
    $upfile_type     = $_FILES["upfile"]["type"];
    $upfile_size     = $_FILES["upfile"]["size"];
    $upfile_error    = $_FILES["upfile"]["error"];
    */

for ($i=0; $i<$count; $i++)
{
    $upfile_name[$i]     = $files["name"][$i];
    $upfile_tmp_name[$i] = $files["tmp_name"][$i];
    $upfile_type[$i]     = $files["type"][$i];
    $upfile_size[$i]     = $files["size"][$i];
    $upfile_error[$i]    = $files["error"][$i];

    $file = explode(".", $upfile_name[$i]);
    $file_name = $file[0];
    $file_ext  = $file[1];

    if (!$upfile_error[$i])
    {
        $new_file_name = date("Y_m_d_H_i_s");
        $new_file_name = $new_file_name."_".$i;
        $copied_file_name[$i] =  $new_file_name.".".$file_ext;      
        $uploaded_file[$i] = $upload_dir.$copied_file_name[$i];

        if( $upfile_size[$i]  > 500000 ) {
            echo("
            <script>
            alert('업로드 파일 크기가 지정된 용량(500KB)을 초과합니다!<br>파일 크기를 체크해주세요! ');
            history.go(-1)
            </script>
            ");
            exit;
        }

        if ( ($upfile_type[$i] != "image/gif") &&
            ($upfile_type[$i] != "image/jpeg")
             )
        {
            echo("
                <script>
                    alert('JPG와 GIF 이미지 파일만 업로드 가능합니다!');
                    history.go(-1)
                </script>
                ");
            exit;
        }

        if (!move_uploaded_file($upfile_tmp_name[$i], $uploaded_file[$i]))
        {
                            print $upfile_tmp_name[$i];
                            print $uploaded_file[$i];
            echo("
                <script>
                alert('파일을 지정한 디렉토리에 복사하는데 실패했습니다.$upfile_tmp_name[$i] AANNDD $uploaded_file[$i]');
                history.go(-1)
                </script>
            ");
            exit;
        }
    }
}

include_once ''; "../lib/dbconn.php";       // dconn.php 파일을 불러옴
    $pdo = db_connect();

if ($mode=="modify")
{
    $num_checked = count($_POST['del_file']);
    $position = $_POST['del_file'];

    for($i=0; $i<$num_checked; $i++)                      // delete checked item
    {
        $index = $position[$i];
        $del_ok[$index] = "y";
    }

            try{           
                $sql = "select * from phptest.concert where num=?";   // get target record
                $stmh = $pdo->prepare($sql);
                $stmh->bindValue(1, $num, PDO::PARAM_STR);
                $stmh->execute();
                $row = $stmh->fetch(PDO::FETCH_ASSOC);
            } catch (PDOException $ex) {
                    print "오류: ".$ex->getMessage();
            }

    for ($i=0; $i<$count; $i++)                 // update DB with the value of file input box
    {

        $field_org_name = "file_name_".$i;
        $field_real_name = "file_copied_".$i;

        $org_name_value = $upfile_name[$i];
        $org_real_value = $copied_file_name[$i];
        if ($del_ok[$i] == "y")
        {
            $delete_field = "file_copied_".$i;
            $delete_name = $row[$delete_field];

            $delete_path = "./data/".$delete_name;

            unlink($delete_path);

                            try{
                            $sql = "update phptest.concert set $field_org_name = ?, $field_real_name = ? where num=?";
            $stmh = $pdo->prepare($sql);
                            $stmh->bindValue(1, $org_name_value, PDO::PARAM_STR);
                            $stmh->bindValue(2, $org_real_value, PDO::PARAM_STR);
                            $stmh->bindValue(3, $num, PDO::PARAM_STR);
                            $stmh->execute();
                            $pdo->commit();
                            } catch (PDOException $ex) {
                                $pdo->rollBack();
                                print "오류: ".$ex->getMessage();
                            }

        }
        else
        {
            if (!$upfile_error[$i])
            {
                                try{
                                    $pdo->beginTransaction();
                                    $sql = "update phptest.concert set $field_org_name = ?, $field_real_name = ?, where num = ?";
                                    $stmh = $pdo->prepare($sql);
                                    $stmh->bindValue(1, $org_name_value, PDO::PARAM_STR);
                                    $stmh->bindValue(2, $org_real_value, PDO::PARAM_STR);
                                    $stmh->bindValue(3, $num, PDO::PARAM_STR);
                                    $stmh->execute();
                                    $pdo->commit();
                                } catch (PDOException $ex) {
                                    print "오류: ".$ex->getMessage();
                                }
            }
        }

    }
            try{
                $pdo->beginTransaction();
                $sql = "update phptest.concert set subject=?, content=?, is_html=? where num=?";
                $stmh = $pdo->prepare($sql);
                $stmh->bindValue(1, $subject, PDO::PARAM_STR);
                $stmh->bindValue(2, $content, PDO::PARAM_STR);
                $stmh->bindValue(3, $html_ok, PDO::PARAM_STR);
                $stmh->bindValue(4, $num, PDO::PARAM_STR);
                $stmh->execute();
                $pdo->commit();

            } catch (PDOException $ex) {
                $pdo->rollBack();
                print "오류: ".$ex->getMessage();
            }

}    //기존내용을 수정하는 경우..
else //신규 추가하는 경우.
{
    if ($html_ok=="y")
    {
        $is_html = "y";
    }
    else
    {
        $is_html = "";
        $content = htmlspecialchars($content);
    }
                try{
                    $pdo->beginTransaction();
                    $sql = "insert into phptest.concert(id, name, nick, subject, content, regist_day, hit, is_html, ";
                    $sql .= " file_name_0, file_name_1, file_name_2, file_copied_0,  file_copied_1, file_copied_2) ";
                    $sql .= "values(?,?,?,?,?,now(),0,?,?,?,?,?,?,?)";
                    $stmh = $pdo->prepare($sql);
                    $stmh->bindValue(1, $_SESSION["userid"],PDO::PARAM_STR);
                    $stmh->bindValue(2, $_SESSION["name"],PDO::PARAM_STR);
                    $stmh->bindValue(3, $_SESSION["nick"],PDO::PARAM_STR);
                    $stmh->bindValue(4, $subject, PDO::PARAM_STR);
                    $stmh->bindValue(5, $content,PDO::PARAM_STR);
                    $stmh->bindValue(6, $is_html,PDO::PARAM_STR);
                    $stmh->bindValue(7, $upfile_name[0],PDO::PARAM_STR);
                    $stmh->bindValue(8, $upfile_name[1],PDO::PARAM_STR);
                    $stmh->bindValue(9, $upfile_name[2],PDO::PARAM_STR);
                    $stmh->bindValue(10, $copied_file_name[0],PDO::PARAM_STR);
                    $stmh->bindValue(11, $copied_file_name[1],PDO::PARAM_STR);
                    $stmh->bindValue(12, $copied_file_name[2],PDO::PARAM_STR);
                    $stmh->execute();
                    $pdo->commit();
                } catch (PDOException $ex) {
                    $pdo->rollBack();
                    print "오류: ".$ex->getMessage();
                }

}
echo "
   <script>
    location.href = 'list.php?page=$page';
   </script>
";

&GT;

directory structure directory structure2

1 个答案:

答案 0 :(得分:0)

$upload_dir = "C:\xampp\htdocs\ch09\data\";
你错过了一个反斜杠。