Viewing 7 replies - 1 through 7 (of 7 total)
  • dannykater had the same problem and couldn’t find anything inside the plugin so I made my own solution for it. here it is maybe not the best solution though.

    if (
    isset( $_POST['cimy_uef_NAME_nonce'])
    && wp_verify_nonce( $_POST['cimy_uef_NAME_nonce'], 'cimy_uef_NAME' )) {
    
    	require_once( ABSPATH . 'wp-admin/includes/image.php' );
    	require_once( ABSPATH . 'wp-admin/includes/file.php' );
    	require_once( ABSPATH . 'wp-admin/includes/media.php' );
    
    	$file = $_FILES['cimy_uef_NAME']['name'];
    	$user = $current_user->ID;
    
    	if($file==true){
    		add_filter('upload_dir', 'my_file_dir');
    		function my_file_dir($upload) {
    			global $current_user;
    
    			$upload['path'] = 'FOLDER_FOR_FILE/';
    			$upload['url'] = 'URL_FORFILE';
    			return $upload;
    		}
    
    		media_handle_upload( 'cimy_uef_NAME', 0);
    		$wpdb->query("UPDATE wp_cimy_uef_data SET VALUE='$file' WHERE USER_ID=$user AND FIELD_ID=1");
    	}
         }
    Thread Starter dannykater

    (@dannykater)

    Thanks!

    A couple of questions. Does your script save the file as Cimy would usually do this? So when I go back to the front end form it will show me that there is a file uploaded and gives me the options to delete it?

    If yes:

    1) My field name is IB60-13-UPLOAD, do I replace at the NAME in capital with my field name? Or the full cimy_uef_NAME_nonce and cimy_uef_NAME?

    2) The folder and url aren’t the same? Cimy usually uploads to a personal file, so I did:

    if (
    	isset( $_POST['cimy_uef_IB60-13-UPLOAD_nonce'])
    	&& wp_verify_nonce( $_POST['cimy_uef_IB60-13-UPLOAD_nonce'], 'cimy_uef_IB60-13-UPLOAD' )) {
    
    		require_once( ABSPATH . 'wp-admin/includes/image.php' );
    		require_once( ABSPATH . 'wp-admin/includes/file.php' );
    		require_once( ABSPATH . 'wp-admin/includes/media.php' );
    
    		$file = $_FILES['cimy_uef_IB60-13-UPLOAD']['name'];
    		$user = $current_user->ID;
    
    		if($file==true){
    			add_filter('upload_dir', 'my_file_dir');
    			function my_file_dir($upload) {
    				global $current_user;
    
    				$username = $current_user->user_login;
    
    				$upload['path'] = 'http://www.belastingteruggave-at.nl/wp-content/Cimy_User_Extra_Fields/'.$username.'/file/';
    				$upload['url'] = 'http://www.belastingteruggave-at.nl/wp-content/Cimy_User_Extra_Fields/'.$username.'/file/';
    				return $upload;
    			}
    
    			media_handle_upload( 'cimy_uef_IB60-13-UPLOAD', 0);
    			$wpdb->query("UPDATE wp_cimy_uef_data SET VALUE='$file' WHERE USER_ID=$user AND FIELD_ID=1");
    		}
    		 }

    But unfortunately not working?

    1) You should change everything if the name isn’t right, my input name is:
    <input name="cimy_uef_AVATAR">

    So if your name is IB60-13-UPLOAD then you should only have that in the php functions.

    2) the path is for the folder on your ftp like this
    $upload['path'] = ABSPATH.'wp-content/Cimy_User_Extra_Fields/'.$current_user->user_login.'/avatar';
    and the url is for the link in the browser window like this
    $upload['url'] = content_url().'/Cimy_User_Extra_Fields'.$current_user->user_login.'/avatar';

    I also made some fixes for files that have space in it’s name you should add these lines to your code to get it working correctly.

    $file = $_FILES['cimy_uef_AVATAR']['name'];
    	$file = str_replace(" ","-", $file);
    	$path = content_url().'/Cimy_User_Extra_Fields/'.$current_user->user_login.'/avatar/'.$file;

    and then also change the media query to this
    $wpdb->query("UPDATE wp_cimy_uef_data SET VALUE='$path' WHERE USER_ID=$user AND FIELD_ID=2");

    Hi grahlie,

    May I know the filename that I should place your code in?

    Thanks 😀

    I’m having the same issue. I’d like to know the same thing as hazgeo.

    I’d really like to get this working, if anyone has the solution that would be awesome.

    I’m getting the following: ERROR: [field] couldn’t be empty.

    So it seems the picture is not uploading.

    Hey Webprese,

    The reason I can’t upload my pdfs on the registration form, was because the form’s enctype wasn’t setup correctly.

    Here’s my fix. You can put it inside your function.php or even better, create you domain-specific plugin and put it there:

    //add enctype to registration form
    function add_post_enctype() {
        echo "<script type='text/javascript'>
    
                    jQuery('#registerform').attr('enctype', 'multipart/form-data');
    
              </script>";
    }
    add_action('wp_footer', 'add_post_enctype');

    Hey guys,

    I got the same issue. But I don’t even see the file uploader on the front- and backend as well. And all I want is to enable users to upload jpg, jpeg, png and pdf-files.

    Tried hazgeo fix but no result.

    I’m using WP 4.2 version.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Files not uploading on front-end’ is closed to new replies.