• Resolved jlohl

    (@jlohl)


    Hello,
    I’d like to upload a text file with user datas to Google Drive.
    A long time ago, Nickboss helped me to do the same with Dropbox and it worked fine.
    I try to use following hook and the path were I want to place the txt file is (/mmm/%userdata1%/%userdata3%/%userdata2%/) I replaced “dropbox” by “gdrive” but unsure of the names

    if (!function_exists('wfu_after_upload_handler')) {
    	function wfu_after_upload_handler($changable_data, $additional_data) {
    		$user = wp_get_current_user();
    		if ( $user->ID == 0 ) $username = "guest";
    		else $username = $user->user_login;
    		$gdrivepath = "mmm/".$additional_data["files"][0]["user_data"][0]["value"]."/".$additional_data["files"][0]["user_data"][2]["value"]."/".$additional_data["files"][0]["user_data"][1]["value"];
    		$deletelocal = false;
    		foreach ( $additional_data["files"] as $file ) {
    			$fileext = wfu_fileext($file["filepath"], true);
    			if ( $fileext == ".wav" ) {
    				$txtpath = preg_replace("/\\$fileext$/", ".txt", $file["filepath"]);
    				$contents = "";
    				foreach ( $file["user_data"] as $userdata )
    					$contents .= ( $contents == "" ? "" : "\r\n" ).$userdata["label"].": ".$userdata["value"];
    				file_put_contents($txtpath, $contents);
    				$fileid = wfu_log_action('include', $txtpath, $user->ID, '', '', get_current_blog_id(), '', null);
    				wfu_gdrive_add_file_to_queue($fileid, $txtpath, $gdrivepath, $deletelocal, "last");
    			}
    		}
    		return $changable_data;
    	}
    	add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2);
    }

    Thanks for help
    JL

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter jlohl

    (@jlohl)

    I was just thinking : WFU has the function to upload all user datas into Google’s file description and this works very well.
    Using this description would be fine but it would mean using the Google API with keys, not a very light solution,….

    Plugin Author nickboss

    (@nickboss)

    Hi, did it work?

    Thread Starter jlohl

    (@jlohl)

    Hello Nick,
    it worked well on Dropbox but I’m not really sure of the exact hook I used (it was a hook that you wrote and that I slightly adapted.

    The .txt file is written on the WordPress uploads but is not moved to the google drive, even if I just set a very basic gdrive path ie only “mmm/”
    I thought it could be an error in the function names ie “wfu_gdrive_add_file_to_queue”, I just changed dropbox to gdrive but not sure it is the right name !

    Plugin Author nickboss

    (@nickboss)

    Can you please share the initial hook, the one with dropbox?

    Nickolas

    Thread Starter jlohl

    (@jlohl)

    Hi Nickolas,

    this one worked on dropbox :

    if (!function_exists('wfu_after_upload_handler')) {
    	function wfu_after_upload_handler($changable_data, $additional_data) {
    		$user = wp_get_current_user();
    		$today = date("Y-m-d");
    		if ( $user->ID == 0 ) $username = "guest";
    		else $username = $user->user_login;
     		$deletelocal = true;
    		$dropboxpath = "mmm/".$username."/".$additional_data["files"][0]["user_data"][1]["value"]."/".$today;
    		foreach ( $additional_data["files"] as $file ) {
    
    			$fileext = wfu_fileext($file["filepath"], true);
    			if ( $fileext == ".wav" ) {
    				$txtpath = preg_replace("/\\$fileext$/", ".txt", $file["filepath"]);
    				$filepath = preg_replace("/\\$fileext$/", ".wav", $file["filepath"]);
    				$contents = "";
    				foreach ( $file["user_data"] as $userdata )
    					$contents .= ( $contents == "" ? "" : "\r\n" ).$userdata["label"].": ".$userdata["value"];
    				file_put_contents($txtpath, $contents);
    				$fileid = wfu_log_action('include', $txtpath, $user->ID, '', '', get_current_blog_id(), '', null);
    				wfu_dropbox_add_file_to_queue($fileid, $txtpath, $dropboxpath, $deletelocal, "last");
    			}
    		}
    		return $changable_data;
    	}
    	add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2);
    Thread Starter jlohl

    (@jlohl)

    About Dropbox, I tried same functions now that worked 3 years ago : it does’nt work anymore !?! I also tried with very basic path on Dropbox or Gdrive “/” or “mmm/” so without any variable in the path.
    So with both Dropbox and Gdrive, the .txt file is correctly created in the WP-content with the good content, good name, good folder but is not send to Dropbox or Gdrive : is (wfu_dropbox_add_file_to_queue) missing something ? How can we check if the file is/was in the upload queue ?
    Could it be that the user is not “system” and so has no rights to write to the cloud ?
    See : log

    • This reply was modified 4 years, 5 months ago by jlohl.
    • This reply was modified 4 years, 5 months ago by jlohl.
    • This reply was modified 4 years, 5 months ago by jlohl.
    • This reply was modified 4 years, 5 months ago by jlohl.
    • This reply was modified 4 years, 5 months ago by jlohl.
    Plugin Author nickboss

    (@nickboss)

    Yes you are right, something has changed.

    Use the following function in place of wfu_dropbox_add_file_to_queue($fileid, $txtpath, $dropboxpath, $deletelocal, “last”);

    wfu_add_file_to_transfer_queue($fileid, $txtpath, "dropbox", $dropboxpath, $deletelocal, "last");

    For Google Drive it should be like this:

    wfu_add_file_to_transfer_queue($fileid, $txtpath, "gdrive", $dropboxpath, $deletelocal, "last");

    Try it and let me know.

    Nickolas

    Thread Starter jlohl

    (@jlohl)

    Bravo Nickboss !
    It works perfectly with both Dropbox and GoogleDrive…

    Efficient support as usual, thanks a lot

    Plugin Author nickboss

    (@nickboss)

    Very nice.

    Regards

    Nickolas

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Hook to upload userdatas to cloud’ is closed to new replies.