Support » Plugin: WordPress File Upload » Change filename upon upload?

  • despeaux

    (@despeaux)


    Hi,

    Is it possible to change the filename upon upload, instead of just directory name?

    Thanks!

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

    (@nickboss)

    Hi, yes it is possible using a hook. What exactly do you want to do?

    Regards

    Nickolas

    despeaux

    (@despeaux)

    Hi Nickolas,

    Awesome! I have a custom field called “Your Location” (a dropdown menu of cities), as well as their logged-in username. So, currently, the files are put in folders named as such: /photos/username-Location/filename.jpg — but I would like it to be just /photos/username-Location.jpg.

    Thank you in advance for any help you can give! I really appreciate it.

    Plugin Author nickboss

    (@nickboss)

    Ok, the code is the following:

    
    if (!function_exists('wfu_before_file_check_handler')) {
    	function wfu_before_file_check_handler($changable_data, $additional_data) {
    		$user = get_userdata($additional_data["user_id"]);
    		if ( $user != false ) {
    			$username = $user->user_login;
    			$filename = wfu_basename($changable_data["file_path"]);
    			$filepath = wfu_basedir($changable_data["file_path"]);
    			$changable_data["file_path"] = $filepath.$username."-".$changable_data["user_data"][0]["value"];
    		}
    		return $changable_data;
    	}
    	add_filter('wfu_before_file_check', 'wfu_before_file_check_handler', 10, 2); 
    }
    

    You have the Free or Pro version of the plugin? instructions on where to put the boave code are different.

    Nickolas

    despeaux

    (@despeaux)

    Hi Nickolas, thank you so much! I currently have the free version but will likely soon purchase the pro version just to support you. Could I have instructions on where to put this code for both versions?

    Plugin Author nickboss

    (@nickboss)

    Ok, for Free version just put the code at the end of functions.php file of your theme.

    Nickolas

    despeaux

    (@despeaux)

    Thank you!

    I was able to add the code, but now when I try to upload a file I get this error: https://www.dropbox.com/s/8sdqhb4fds6jh0j/chrome_2017-07-27_15-24-53.png?dl=0

    Do you know what may be causing this?

    Thanks again.

    Plugin Author nickboss

    (@nickboss)

    what is the filename of the file you tried to upload?

    Nickolas

    despeaux

    (@despeaux)

    Hi Nickolas,

    I tried a few, but for example, “photo.jpg” did not work. I still get “File not allowed.”

    In the plugin preferences, I have it set to allow the following filetypes: *.jpg,*.jpeg,*.png,*.gif

    Plugin Author nickboss

    (@nickboss)

    Hi, can you send the URL of the page to try myself?

    Nickolas

    despeaux

    (@despeaux)

    Hi Nickolas,

    Unfortunately I can’t, as this is an internal (Intranet) site. I will try to repo on a public site.

    Is there any other data I could provide you that would help troubleshoot?

    Thanks!

    despeaux

    (@despeaux)

    Hi Nickolas,

    I installed the plugin to a public site, set it up with the same settings and PHP code, and was able to repo the issue. The page is here: https://despeaux.consulting/pingpong/file-upload/

    As you can see I am getting the same upload error.

    Thank you for your assistance!
    Cliff

    despeaux

    (@despeaux)

    Hi Nickolas,

    Very interesting — I am able to upload a file successfully if I am not logged in. I see the files you loaded (although it only renamed the folder, not the file itself).

    When I am logged in, I am getting that error again.

    Thanks for your support. At this point I think I’ll just live with the renaming on the folder only and find a script to rename the files based on the folder. It’s not a big deal.

    If you are still interesting in troubleshooting I can give you an admin login to that site. No worries if not.

    Thanks!
    Cliff

    Plugin Author nickboss

    (@nickboss)

    Hi Cliff, yes if you don’t mind.

    Regards

    Nickolas

    despeaux

    (@despeaux)

    Thanks! I just emailed you a login.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Change filename upon upload?’ is closed to new replies.