mkdir()PHP函数不适用于Windows

时间:2014-02-11 17:58:31

标签: php

我现在已经尝试了几天,弄清楚为什么我的mkdir()函数在下面的代码中不起作用。我希望你们能够指出我正确的方向。我还不确定我是否需要更改php.ini文件中的任何内容才能让这个野兽正常工作。

function create_album()
{
try
{
    if( isset( $_SESSION['session_id'] ) && $_SESSION['permissions'] ==  0  )
    {
        if( isset( $_POST['album_name'] ) && ( file_exists( $_FILES['cover_photo']['tmp_name'] ) || is_uploaded_file($_FILES['cover_photo']['tmp_name'] ) ) )
        {
            $db = honneyconnect( ) ;
            if( mysqli_connect_error() )
            {
                throw new Exception( "Could not connect to the database") ;
            }
            else
            {
                $unique = false ;
                /*while( !$unique )
                {
                    $key = rand( )  ;
                    $query = "select * from albums where album_id = '".$key."'";
                    $result = $db->query( $query ) ;
                    if( !$result )
                    {
                        $unique = true ;
                    }
                }*/
                $key = 5 ;
                if( !mkdir( "/www/honeysproject/".$_POST['album_name']  ) )
                {
                    throw new Exception( "Failed to create the album.  Please try again." ) ;
                }
                else
                {

                    if( !move_uploaded_file($_FILES["cover_photo"]["tmp_name"], "C:/wamp/www/HoneysProject/".$_POST['album_name']."/" . $_FILES["cover_photo"]["name"]) )
                    {
                        throw new Exception( "There was a problem uploading the file" ) ;
                    }
                    else
                    {
                        $query = 'insert into albums values ("'.$key.'","'.$_POST['album_name'].'", "'.$_FILES['cover_photo']['name'].'")';
                        $album = $db->query( $query ) ;
                        if( !$album )
                        {
                            throw new Exception( "Failed to create the ".$_POST['album_name']." album.  Please check your input and try again." ) ;
                        }
                        else
                        {
                            echo "<img src='/HoneysProject/".$_POST['album_name']."/".$_FILES['cover_photo']['name']."'><a cless ='button' href='/HoneysProject/uploadphotos.php?album_id=".$key."'>Upload Photos</a><a class='button' href='/HoneysProject/albumedit.php?album_id=".$key."'>Edit Album</a>" ;
                        }
                    }

                }


            }
        }
        else
        {
            echo '<div class="data_entry">
                        <form id="new_album" method="post" action="createalbum.php" enctype="multipart/form-data" />
                        <input type="hidden" name="MAX_FILE_SIZE" value="50000000" />
                        <table>
                        <tr><td>Album Name:</td><td><input type="text" size="10" name="album_name" /></td></tr>
                        <tr><td>Choose a Default Photo:</td><td><input type="file" name="cover_photo" id="photo" /></td></tr>
                        <tr><td><input type="submit" value="Submit Data" /></td></tr>
                        </table>

                        </form></div>' ;
        }
    }
}
catch( Exception $error ) 
{
    echo "<div class='error'>".$error."</div>" ;
    echo '<div class="data_entry">
                        <form id="new_album" method="post" action="createalbum.php" enctype="multipart/form-data" />
                        <input type="hidden" name="MAX_FILE_SIZE" value="50000000" />
                        <table>
                        <tr><td>Album Name:</td><td><input type="text" size="10" name="album_name" value="'.$_POST['album_name'].'"/></td></tr>
                        <tr><td>Choose a Default Photo:</td><td><input type="file" name="cover_photo" id="photo" /></td></tr>
                        <tr><td><input type="submit" value="Submit Data" /></td></tr>
                        </table>

                        </form></div>' ;

}
}

2 个答案:

答案 0 :(得分:3)

windows文件系统与linux完全不同:

if( !mkdir( "/www/honeysproject/".$_POST['album_name']  ) )

我认为这应该是:

if( !mkdir( "c:\\www\\honeysproject\\".$_POST['album_name']  ) )

答案 1 :(得分:0)

如果你想在Windows上执行此操作,你应该把正确的路径放在&#34; / www / honeysproject /&#34;

你应该写下这样的东西:

if( !mkdir( "c:\\www\\honeysproject\\".$_POST['album_name']  ) )

两个斜杠是保险箱方式