Support » Plugin: WordPress File Upload » Show Image after Upload

  • Resolved phantomb

    (@phantomb)


    Is it possible to show the last uploaded image, after the upload is complete, in the same page the upload form is in? Can it be shown in a different page?

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

    (@nickboss)

    Hi, the following script uses a plugin hook to show the uploaded image right below the upload form. You need to put it at the end of functions.php file of your theme

    if (!function_exists('wfu_after_upload_handler')) {
    	function wfu_after_upload_handler($changable_data, $additional_data) {
    		foreach ( $additional_data["files"] as $file ) {
    			if ( $file["upload_result"] == "success" || $file["upload_result"] == "warning" ) {
    				$url = str_replace(ABSPATH, site_url().'/', $file["filepath"]);
    				$changable_data["js_script"] = "
    					var block = document.getElementById('wordpress_file_upload_block_1');
    					var div = document.getElementById('wfu_img_container');
    					if (div) div.parentNode.removeChild(div);
    					div = document.createElement('DIV');
    					div.id = 'wfu_img_container';
    					var img = document.createElement('IMG');
    					img.src = '$url';
    					div.appendChild(img);
    					block.parentNode.insertBefore(div, block.nextElementSibling);
    				";
    				break;
    			}
    		}
    		return $changable_data;
    	}
    	add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2);
    }

    Showing it in another page requires more customization, but it could be done.

    Regards

    Nickolas

    This worked just fine. Much appreciated!

    Plugin Author nickboss

    (@nickboss)

    Ok I am glad.

    Regards

    Nickolas

    anefarious1

    (@anefarious1)

    Can I ask…

    Normally… you’d have to manually go in and attach an uploaded image to a post or page? There is no settings option that takes care of this?

    I ask because I tried the setting, “Attach Uploaded Files To Post” but it doesn’t work. Thanks

    Plugin Author nickboss

    (@nickboss)

    Hi, in the language of WordPress, attaching an image to a post means that it is linked with the post (you can have many images attached to the same post). So then, an image gallery plugin can find these images and display them in the post.

    For instance, if you put the shortcode [gallery] under the upload plugin, it will display the images attached to the post.

    Regards

    Nickolas

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