Support » Plugin: WordPress File Upload » Run python script with file and user e-mail

  • Resolved fblanco

    (@fblanco)


    Hello!

    I have an issue similar to this one.

    Im trying to run a python script that takes the uploaded file and the user’s e-mail as input.

    if (!function_exists('wfu_after_upload_handler')) {
    	function wfu_after_upload_handler($changable_data, $additional_data) {
    		$files = $additional_data["files"];
    		$result = "";
    		foreach ( $files as $file )
    			if ( $file["upload_result"] == "success" || $file["upload_result"] == "warning" ) {
    				$file_path = $file["filepath"];
    				exec('python path/to/script.py', $result, $return_var);;
    				break;
    			}
    		if ( $result != "" )
    			foreach ($result as $line) {
           			$changable_data["js_script"] = 'console.log("'.$line.'");';
      			}
    		return $changable_data;
    	}
    	add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2);
    }

    For now, the script is a simple helloworld just for testing, but I’ve been unable to make it work. I’m new to php and WordPress so my questions may be a bit silly, but here they are:

    1) Is path/to/script.py relative to wp-content?

    2) Eventually I’ll need to get the logged user’s email (or some kind of user data). I assumed it should be somewhere in ‘$additional_data[user-data]’. I tried using this

    console.log("'.$additional_data["user_data"].'");

    to take a look inside ‘user_data’ but I’m sure I’m doing something wrong, since it’s not working.

    I’m using the free version of the plugin.

    Thanks in advance! Any help will be greatly appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • fblanco

    (@fblanco)

    Small Update.

    I managed to get the user’s email using wordpress functions, so that’s done.

    Plugin Author nickboss

    (@nickboss)

    Hi, are you sure that your system allows to execute exec function?

    Put PHP command error_log($file_path); above exec command to check that the block is executed. You should see output at /wp-content/debug.log file.

    Regards

    Nickolas

    Hello! Yes, it does!

    In the end I managed to use full paths and then moved on to relative paths once I figured what the root directory was.

    Thanks for your reply!

    Plugin Author nickboss

    (@nickboss)

    Ok nice.

    Regards

    Nickolas

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.