okay...
is this the logic you want?
Code:
was form submitted?
yes:
is "guess" a file?
yes:
redirect to the file
no:
create the file*
*not sure I understand the point of this.
will this be an empty file?
or are you adding contents somehow?
allowing a user to add contents (to a .php file) is very dangerous
PHP Code:
<?php
if( isset( $_POST['submit'] ) && !empty( $_POST['guess'] ) ){
$root = $_SERVER['DOCUMENT_ROOT'];
$host = $_SERVER['HTTP_HOST'];
$path = '/folder';
$ext = '.php';
$guess = preg_replace( '#[^-_ A-Za-z0-9]#u','',$_POST['guess'] );
if( file_exists( $root.$path.$guess.$ext ) ){
header( "Location: http://$host.$path.$guess.$ext" );
exit;
}else{
$handle = fopen( $root.$path.$guess.$ext,'w' );
// . . .
}
}
in your original example, you're leaving case alone when looking for a file, and lowercasing everything when creating it. You should do one or the other. This makes a big difference on linux (i.e., most webservers), where everything is case-sensitive (as opposed to Windows, where case doesn't matter).
Edit:
glad you got it working.
Bookmarks