• Resolved ffenton

    (@ffenton)


    I have posted about this on the main website, but so far no reply.

    Basically I am wanting to resize images after they have uploaded.
    Following this post https://wordpress.org/support/topic/possible-to-use-uploaded-file-after-upload-is-success I have installed Code Snippets and created the following snippet just as a test to see if I can get that to work before addressing resizing images. Unfortunately the post went to private email so solution was never posted.
    I am having the same problem in that images are uploaded but no log file is created. (I even tried creating an empty log file first)

    if (!function_exists('wfu_before_file_upload_handler')) {
        function wfu_before_file_upload_handler($file_path, $file_unique_id) {
          $_SESSION['wfu_tempfiles'][$file_unique_id] = $file_path;
          return $file_path;
    	  $message="TEST MESSAGE 1";
    	  wfu_debug_log($message);
      }
      add_filter('wfu_before_file_upload', 'wfu_before_file_upload_handler', 10, 2);
    }
    if (!function_exists('wfu_after_file_upload_handler')) {
      function wfu_after_file_upload_handler($changable_data, $additional_data) {
        if ($additional_data['upload_result'] == 'success' && isset($_SESSION['wfu_tempfiles'][$file_unique_id]) && $_SESSION['wfu_tempfiles'][$file_unique_id] != '') {
    	  $file_contents = file_get_contents($_SESSION['wfu_tempfiles'][$file_unique_id]);
         $message="TEST MESSAGE 2";
    	  wfu_debug_log($message);
    
    	}
    	return $changable_data;
      }
      add_filter('wfu_after_file_upload', 'wfu_after_file_upload_handler', 10, 2);
    }

    All I need to be able to do is grab the location of each uploaded file and pass it to some php code for resizing.

    https://wordpress.org/plugins/wp-file-upload/

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

    (@nickboss)

    Hi, Where did you send the first post? I never received it. Let me check the code you created and get back to you soon.

    Plugin Author nickboss

    (@nickboss)

    As i see, “TEST MESSAGE 1” will never be logged because you have already returned from the function because of the previous return command.

    In wfu_after_file_upload_handler function, $file_unique_id is not defined. Add the following code before the if statement:

    $file_unique_id = $additional_data["file_unique_id"];

    Test it and let me know.

    Thread Starter ffenton

    (@ffenton)

    Thanks Nick, that set me on the right path and I now have it working as wanted.
    For anyone else wanting to resize images after upload this is what I ended up with.

    if (!function_exists('wfu_before_file_upload_handler')) {
        function wfu_before_file_upload_handler($file_path, $file_unique_id) {
          $_SESSION['wfu_tempfiles'][$file_unique_id] = $file_path;
          return $file_path;
      }
      add_filter('wfu_before_file_upload', 'wfu_before_file_upload_handler', 10, 2);
    }
    if (!function_exists('wfu_after_file_upload_handler')) {
      function wfu_after_file_upload_handler($changable_data, $additional_data) {
    	$file_unique_id = $additional_data["file_unique_id"];
        if ($additional_data['upload_result'] == 'success' && isset($_SESSION['wfu_tempfiles'][$file_unique_id]) && $_SESSION['wfu_tempfiles'][$file_unique_id] != '') {
         $filepath= $_SESSION['wfu_tempfiles'][$file_unique_id];
    	 //now that we have the path to uploaded file we can resize it using our resizeImage function in our functions.php file
    	 resizeImage($filepath, $filepath, 600, 600);
    
    	}
    	return $changable_data;
      }
      add_filter('wfu_after_file_upload', 'wfu_after_file_upload_handler', 10, 2);
    }

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Using filters to process uploaded images’ is closed to new replies.