1

Just tried out the blueimp "out of the box" files. With a few hurdles, I got the plugin to work on my site.

In my application, I want to store the uploaded files in specific directories based on the file name.

The PHP code to do this is pretty straight forward:

function StoreAudioFiles()
{
$TempFileName = $_FILES['file']['tmp_name'];    
$OriginalFileName= $_FILES['file']['name']; 
$TheFolderName=MyCustomFunction($OriginalFileName);  
move_uploaded_file($TempFileName,$TheFolderName.$OriginalFileName);    
}

I have no idea where to modify the 'out-of-the-box' file "UploadHandler.php" to insert my code. Given the fact that the file is 55 pages long when opened in Word, any help would be appreciated.

David

Cymro
  • 1,201
  • 1
  • 11
  • 29

1 Answers1

1

I worked out a solution and am posting it here for others to use.

In the index.php file that comes with blueimp, add functions after the object is created. Here's what I did:

require('UploadHandler.php');
$upload_handler = new UploadHandler();

//Now Add whatever custom functionality you want from here on.
MoveFiles();

function MoveFiles()
{
$UploadDir="files/";
$TheHandle=opendir($UploadDir);
while (False !== ($FileName = readdir($TheHandle))) MoveThisFile($FileName);   
}

function MoveThisFile($TheFileName)
{
if(strlen($TheFileName)<4) return;
$UploadFilePath='mysite/server/php/files/';
$TheFolderName=MyCustomFolderName($TheFileName); 
$OriginalFileName=$UploadFilePath.$TheFileName;  
$TargetFileName=$TheFolderName.$TheFileName;  
rename($OriginalFileName,$TargetFileName);    
}
Cymro
  • 1,201
  • 1
  • 11
  • 29