Reputation: 161
I've been trying for a couple days now to figure out exactly why my mkdir() function in the following code isn't working. I'm hoping you guys might be able to point me in the right direction. I'm also not sure if I need to alter anything in the php.ini file in order to get this beast to work correctly.
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>' ;
}
}
Upvotes: 0
Views: 99
Reputation: 2230
the windows filesystem is quite different from linux:
if( !mkdir( "/www/honeysproject/".$_POST['album_name'] ) )
i think this should be:
if( !mkdir( "c:\\www\\honeysproject\\".$_POST['album_name'] ) )
Upvotes: 3
Reputation: 425
if you want to execute this on windows , you should put the right path not "/www/honeysproject/"
you should put something like :
if( !mkdir( "c:\\www\\honeysproject\\".$_POST['album_name'] ) )
two slashes is safes way
Upvotes: 0