uwePhillPhelps / uweAudioSegmentation

applescript to monitor dropbox, PHP interface to manage tools (FAAD/LAME/shnTool/mp3splt) which convert & segment uploaded audio
1 stars 0 forks source link

filenames in dropbox #1

Open uwePhillPhelps opened 12 years ago

uwePhillPhelps commented 12 years ago

files put in dropbox should be monitored for anomolies (longer than FAT32 will support, code exucution as part of arguments, etc)

uwePhillPhelps commented 12 years ago

php processing script used to do this:

    // convert the filename to lowercase for substring comparisons
    $lowercasefilename = strtolower($file->getFilename());

    // fixing filename - 20 character max
        // process the filename to strip out any "unsafe" or "unwise" content
        // e.g. HTML tags, spaces, non alphanumeric characters
        $lowercasefilename = strip_tags($lowercasefilename);
        $newFilename = preg_replace("/[^\.a-zA-Z0-9]/", "", $lowercasefilename);

        // if characters >= 20 combine first 10 then last 10
        $newFilenameLen = strlen($newFilename);
        if ( $newFilenameLen >= 20 )
        {
            $newFilename = substr( $newFilename, 0, 10 )
                        . substr( $newFilename, -10, 10);
        }

        $filenameDelta = strlen($file->getFilename()) - strlen($newFilename);
        $newPathname = $file->getPath().'/'.$newFilename;

        // rename file to the "safe" filename
        if ($filenameDelta != 0)
        {
            rename($file->getPathname(), $newPathname);

            writeTableRow('--', 'Fixing filename', 
                "Original filename: " . $file->getFilename() . "<br>\n"
                . "Renamed filename: " . $newFilename . "<br>\n", 
                "removed $filenameDelta characters");
        }