WordPress.org

Support

Support » Plugins and Hacks » Form Manager » [Plugin: WordPress Form Manager] Naming uploaded files based on form data

[Plugin: WordPress Form Manager] Naming uploaded files based on form data

  • I’ve set up a form on a website I’m developing for applicants to an opera program to fill out a upload audio recordings. So far it seems to function for the most part. However, I’ve noticed that when I use the default naming scheme (%filename%) it tends to cause problems when the files are uploaded to the server if, for example, the file has an apostrophe in the name (e.g. “Dio, che nell’alma infondere.mp3” becomes “Dio, che nell\’alma infondere.mp3”, which will return a 404 when a user or admin clicks on the file link). The form asks for first and last name; would it be possible to automatically save files as %First Name% %Last Name% Audio Recording 1 (m-d-y-h-i-s).mp3, or something similar?

    Thank you very much; the plugin is absolutely wonderful and has otherwise deployed flawlessly.

    http://wordpress.org/extend/plugins/wordpress-form-manager/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Rockstaru,

    I’m having the same troubles with file uploads containing apostrophe’s. Have you found a solution?

    Not an ideal one, but it fixes the problem. In the file.php file (should be under the types folder in the form-manager plugin folder), there is a function that reads as follows:

    protected function getFormattedFileName($uniqueName, $itemInfo){
    $pathInfo = pathinfo($_FILES[$uniqueName][‘name’]);
    $fileNameFormat = trim($itemInfo[‘extra’][‘name_format’]) == “” ? get_option( ‘fm-file-name-format’ ) : trim($itemInfo[‘extra’][‘name_format’]);
    if($fileNameFormat == “%filename%”){
    $newFileName = $pathInfo[‘filename’];
    }
    else{
    $fileNamePos = strpos($fileNameFormat, ‘%filename%’);
    if($fileNamePos !== false){
    if($fileNamePos > 0){
    $before = substr($fileNameFormat, 0, $fileNamePos);
    $after = substr($fileNameFormat, $fileNamePos + 10, strlen($fileNameFormat) – $fileNamePos – 10);
    }
    else{
    $before = “”;
    $after = substr($fileNameFormat, -1 * (strlen($fileNameFormat) – 10));
    }
    }
    $newFileName = “”;
    if($before != “”)
    $newFileName.= fm_get_time($before);
    if($fileNamePos !== false)
    $newFileName.= $pathInfo[‘filename’];
    if($after != “”)
    $newFileName.= fm_get_time($after);
    }
    $newFileName.= ‘.’.$pathInfo[‘extension’];

    return $newFileName;
    }

    Add the following before the final “return $newFileName;”

    $newFileName = preg_replace(“/[^A-Za-z0-9_-\s.]/”, “”, $newFileName);

    This essentially deletes all non-alphanumeric characters and spaces from the file name (and preserves periods, so the filetype is preserved). In the above example, “Dio, che nell’alma infondere.mp3” becomes “Dio che nellalma infondere.mp3.” Again, not an ideal solution, but it works.

    Wow – thank-you for helping me here. I’m not tech-qualified enough to make this adjustment, but my pastor helped me with some other coding, and I think he’ll do this for me too…

    Thanks again!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: WordPress Form Manager] Naming uploaded files based on form data’ is closed to new replies.
Skip to toolbar