Jump to content
xisto Community
Sign in to follow this  
Neutrality

Alphanumeric Upload Sorting

Recommended Posts

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):

UPLOAD.PHP<?phpecho "<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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.