Support » Plugin: Contact Form DB » Uploaded file moved to another location and add llink to file

  • Hello,
    at first I must say: your plugin is great.

    I do modification on uploaded file via Contact Form 7. I use your code from: https://cfdbplugin.com/?page_id=794.

    File is moved to new location. But I will add new URL to the file in your table in admin. So, if I clicked to file name in table, I can download the file.

    Please, can you help me with this?

    Here is code, that I use:

    function cfdbFilter($formData){
    if($formData && ‘Udelenie grantu’ == $formData->title){
    $uploaddir=’/path/to/directory’;

    $formCopy=clone $formData;
    $path=pathinfo($formCopy->uploaded_files[‘attachment’]);
    $filename=$path[‘basename’];
    $filename_new = file_newname($uploaddir, $filename);

    $newname = $uploaddir.$filename_new;

    copy($formCopy->uploaded_files[‘priloha’],$newname);

    $formCopy->posted_data[‘priloha’] = $filename_new;
    //$formCopy->posted_data[‘fileurl’] = ‘http://www.my-site.com/dir-upload/’;

    unset($formCopy->uploaded_files[‘attachment’]);
    return $formCopy;
    }

    return $formData;
    }
    add_filter(‘cfdb_form_data’,’cfdbFilter’);

    // add counter to file name if exist
    function file_newname($path, $filename){
    if ($pos = strrpos($filename, ‘.’)) {
    $name = substr($filename, 0, $pos);
    $ext = substr($filename, $pos);
    } else {
    $name = $filename;
    }

    $newpath = $path.’/’.$filename;
    $newname = $filename;
    $counter = 0;
    while (file_exists($newpath)) {
    $newname = $name .’_’. $counter . $ext;
    $newpath = $path.’/’.$newname;
    $counter++;
    }

    return $newname;
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    Please use the “code” button to format code that you post. Otherwise it is hard to read.

    This line is to for you to set the URL for downloading your file from where you place it.
    //$formCopy->posted_data[‘fileurl’] = ‘http://www.my-site.com/dir-upload/’;

    But I don’t think it appears as a clickable link in the administration page. If using a shortcode, you can add some JavaScript to make the link active. See: https://cfdbplugin.com/?p=867

    Sorry for bad code formating. I do it with shortcode and little bit javascript.
    Many thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Uploaded file moved to another location and add llink to file’ is closed to new replies.