Extract variable from uploaded filename

Hi there

Sorry, I am very new to php, so please bear with me.

I am building a site for users to upload files to a server. These files need to go into specific directories. The directories are created by php based on the logged in user’s information as extracted from the Mysql database.

However, there is one variable that I am struggling to extract. The file names of the files being uploaded have a 3 character prefix which indicates the intended recipient of the file (these 3 characters have been pre-determined since there are only a handful of intended recipients). I want to be able to extract these characters from the file name, and based on the values of these characters, email the intended recipient to alert them that the file has arrived.

Is it possible (and if so, how), to create a variable from an uploaded file name which can then be compared with a list to determine who the file is for?

Any assistance will be greatly appreciated.

Inspector Mills

You could use substr() to get the prefix from the file name. Have a read of [URL=“http://articles.sitepoint.com/article/handle-file-uploads-php”]this SitePoint Article on File Uploads.

Thanks for the quick comeback - you pointed me in the right direction.

I have used the following code, and it works fine:

$filename = $_FILES[‘userfile’][‘name’]; //the original filename
$recipient = substr($filename, 0, 3); //the first 3 characters of the filename

Thanks again.

Inspector Mills