Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Author nickboss

    (@nickboss)

    Hi, I do not quite understand what you want to do. Can you please provide more details.

    Regards

    Nickolas

    Thread Starter navyspitfire

    (@navyspitfire)

    How can I change the filename of a file that is uploaded?

    Plugin Author nickboss

    (@nickboss)

    Hi, here are instructions for the free version:

    1. Create an additional field where the user will insert the name.
    2. Install a 3rd party plugin, called Code Snippets. It will be used for implementing the filters.
    3. Go to the Dashboard page of Code Snippets and add a new snippet. Give it any name you want.
    4. Add the following code inside the Code Box:

    if (!function_exists('wfu_before_file_check_handler')) {
    	function wfu_before_file_check_handler($changable_data, $additional_data) {
    		$filepath = wfu_basedir($changable_data["file_path"]);
    		$fileext = wfu_fileext($changable_data["file_path"], true);
    		$new_filename = sanitize_file_name(trim($changable_data["user_data"][0]["value"]));
    		if ( $new_filename != "" ) $changable_data["file_path"] = $filepath.$new_filename.$fileext;
    		else $changable_data["error_message"] = "File not uploaded! Invalid name entered.";
    		return $changable_data;
    	}
    	add_filter('wfu_before_file_check', 'wfu_before_file_check_handler', 10, 2);
    }

    The above filter will replace the filename with the name entered in the field. It will check the entered name for invalid characters. If it is empty, then the upload will fail.

    5. Save and Activate the filter.

    Nickolas

    Thread Starter navyspitfire

    (@navyspitfire)

    Is there anyway I can set the filename myself?

    That code, would that go in the functions.php file? I rather enter it myself than download a plugin to do it.

    Plugin Author nickboss

    (@nickboss)

    do you want to be able to change the filename of a file uploaded by another user?

    btw, yes you can put the code inside functions.php

    Thread Starter navyspitfire

    (@navyspitfire)

    Yes, I want to change the filename of a file uploaded by another user.

    Plugin Author nickboss

    (@nickboss)

    The plugin has a File Browser in Dashboard from where you can see the files, after they are uploaded and you can also rename/delete/download them. Is this what you want?

    Thread Starter navyspitfire

    (@navyspitfire)

    No I am trying to automate the filename change, so when the user uploads a file it will automatically rename it to something I already designated.

    Plugin Author nickboss

    (@nickboss)

    ok, so the above filter can also do that, how will the file be renamed?

    Nickolas

    Thread Starter navyspitfire

    (@navyspitfire)

    I’m hoping I can use jquery to take whatever text they input into their “name” field and rename it like that. Something like “firstname”-video.mp4.

    Plugin Author nickboss

    (@nickboss)

    well the change of filename is done on the server using the above filter with PHP language. Of course you can tailor the code to your needs, so you can rename the file to whatever you want, like the one you requested above.

    jQuery executes on your browser, you can also use it but it is not so straightforward and requires some tweaks, is there a reason why you want to use jQuery?

    Thread Starter navyspitfire

    (@navyspitfire)

    It’s the only way I know how to grab whatever the user enters into the name input and copy it. The new filename will become $new_filename?

    Plugin Author nickboss

    (@nickboss)

    yes in the above code $new_filename is the value that the user enters in the field which becomes the new filename

    I’m having trouble finding the Code Snippets plugin – it maybe was updated/upgraded and now is n/a? Can you link me to that?

    • This reply was modified 7 years, 10 months ago by simonmaxhill.
    Plugin Author nickboss

    (@nickboss)

    Hi, you have the Free version?

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Change file name’ is closed to new replies.