我一直在嘗試了幾天,現在才弄清楚爲什麼我的mkdir()函數在下面的代碼中不起作用。我希望你們能夠把我指向正確的方向。我也不確定是否需要更改php.ini文件中的任何內容,以便讓這隻野獸正常工作。mkdir()PHP函數不能在Windows上工作
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>' ;
}
}
存在的問題是'/'在窗口有反斜線\也有對'/ www' – demonking