not working...
Someone please explain and correct why I can successfully create folders but upload to the wrong place..
here are my scripts:
(forms, first ask for the folder name to be created, second asks for file to be created)
print "\n<form ENCTYPE=\"multipart/form-data\" action=\"" . $PHP_SELF . "\" method=\"post\">";
print "\n<INPUT TYPE=\"hidden\" name=\"task\" value=\"setfolder\">";
echo "<TR><TD><font size =\"-1\" face=\"arial, helvetica\">Create directory</font></td><td>";
echo "<INPUT TYPE=\"TEXT\" NAME=\"mkdirfile\" size=\"40\">";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
print "\n<input type=\"submit\" Value=\"Create/Enter Your Database\">";
print "\n</form>";
--
function form($error=false) {
global $PHP_SELF,$my_max_file_size;
if ($error) print $error . "<br><br>";
print "\n<form ENCTYPE=\"multipart/form-data\" action=\"" . $PHP_SELF . "\" method=\"post\">";
print "\n<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $my_max_file_size . "\">";
print "\n<INPUT TYPE=\"hidden\" name=\"task\" value=\"upload\">";
print "\n<P>Upload a file";
print "\n<BR>NOTE: Max file size is " . ($my_max_file_size / 1024) . "KB";
print "\n<br><INPUT NAME=\"the_file\" TYPE=\"file\" SIZE=\"35\"><br>";
print "\n<input type=\"submit\" Value=\"Upload\">";
print "\n</form>";
(upload and create folder function)
function upload($the_file) {
global $basedir,$the_file_name;
$error = validate_upload($the_file);
if ($error) {
form($error);
} else { # cool, we can continue
if (!@copy($the_file, $basedir.$wdir . "/" . $the_file_name)) {
form("\n<b>Something barfed, check the path to and the permissions for the upload directory</b>");
} else {
list_files();
form();
}
}
} # END upload
function createfolder($wdir,$mkdirfile)
{
global $basedir
if(file_exists($basedir.$wdir.$mkdirfile))
{
$lastaction = "The directory $wdir$mkdirfile allready exists.";
}
############### Create directory
else
{
$lastaction = "Created the directory $wdir$mkdirfile";
mkdir($basedir.$wdir.$mkdirfile,0775);
}
}
--
(If statements)
switch($task) {
case 'setfolder':
createfolder($wdir,$mkdirfile);
form();
break;
case 'upload':
upload($the_file);
break;
}
The folder creates successfully after the first submit, but then the files are uploaded to the ROOT directory ($basedir) instead of the newly created one.