This is what the script does: when a file is uploaded from a form, this script checks
what directory it should go into. So before the upload occurs, the alphanumeric
directories are created ( only once, of course). Here it is in code (Please note that this just example code):

CODE

UPLOAD.PHP

<?php

echo "<form action='upload-sort.php' method='get' enctype='multipart/form-data'>";
echo "Upload a file: <input type='file' name='upload'>";
echo "</form>";

?>

UPLOAD-SORT.PHP

<?php

$alphaNum = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);

$arraySize = count($alphaNum);

for($n=0; $n<$arraySize; $n++)
{
    if(!directory_exists($alphaNum[$n])) mkdir($alphaNum[$n]);
    if(substr($_FILES['upload']['name'], -4) != ".exe")
    {
         if(substr($_FILES['upload']['name'], 1) == $alphaNum[$n])
         copy($_FILES['upload']['tmp_name'], $_FILES['upload']['name']);
    }
}

?>


I'm hoping that the $_FILES array works. If you have any trouble with that variable, use the $HTTP_POST_FILES instead and see if it works. If it doesn't, come back here and I'll correct that problem.

 

 

 


Reply