I'm trying to create a predefined directory with mkdir();
mkdir(); should create directory or folder as inserted in the text box. My code is as following:
[ATTACH]5139[/ATTACH]
if (isset($_FILES['file_upload']) && isset($_POST['predefined_value'])) {
$dir = isset($_POST['predefined_value']) ;
$directory = "site.com/$dir/";
if (!is_dir($directory)) mkdir($directory, 0777); /// It always creates numeric directory "1" based on the variable $dir
$max_size = 1024;
$allowtype = array('bmp', 'gif', 'jpg', 'jpeg');
$rezult = array();
for($f=0; $f<count($_FILES['file_upload']['name']); $f++) {
$nume_f = $_FILES['file_upload']['name'][$f];
if (strlen($nume_f)>3) {
$type = end(explode('.', strtolower($nume_f)));
if (in_array($type, $allowtype)) {
if ($_FILES['file_upload']['size'][$f]<=$max_size*1028) {
if ($_FILES['file_upload']['error'][$f]==0) {
$thefile = $directory . '/'. $nume_f;
if (!move_uploaded_file ($_FILES['file_upload']['tmp_name'][$f], $thefile)) {
$result[$f] = 'The file '. $nume_f. 'Unable to copy, try again';
}
else {
$result[$f] = ''.$nume_f.'';
}
}
}
else { $result[$f] = 'The file '. $nume_f. ' Unpermitted size, <i>'. $max_size. 'KB</i>'; }
}
else { $result[$f] = 'The file '. $nume_f. 'Invalid file type'; }
}
}
$_SESSION['result'] = implode($result);
header('Location: '.basename($_SERVER['PHP_SELF']).'?file=uploaded');
}
if (isset($_GET['file']) && isset($_SESSION['result'])) {
echo 'Uploaded File: '. $_SESSION['result'];
unset($_SESSION['result']);
} else {
echo "Select file to upload";
}
}
<form id="uploadform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<input type="text" name="predefined_value" value="<?php echo isset($_POST['predefined_value']);?>" size="5" />
<input name="upload_file[]" type="file" class="upload_file" size="50" />
<input type="submit" value="Upload" id="submit" />
</form>
The problem is that mkdir(); always creates a numeric directory named "1" on form submit no matter whatever value I insert in the text field name="predefined_value"
Are these the inappropriate from input name and value those causing the problem?
What's going wrong here?
fur.png