[wp-hackers] Front end file handling

Tom Barrett tcbarrett at gmail.com
Wed Nov 14 17:18:31 UTC 2012


Mike,
The file is sitting on the server (local to WordPress) rather than with the
user at the point where I need to do my attachment.

Alex,
I can see that I am confusing myself a little (media_sideload_image vs
media_handle_sideload). Additionally was sidetracked by function call to
@wp_read_image_metadata($file) which is supported in image.php (which I had
not included and therefore failed silently).

Thank you both!

I wrote my own version of media_sideload_image() which seems to be working.

add_action( 'post_post_update', 'tcb_snoop_post_submission', 10 );
function tcb_snoop_post_submission( $postarr ){
  //
http://www.example.com/wp-content/uploads/supplier-pics/ahgajhvbjhb345345/mypic1.png
  $picurl = $postarr['supplier_picture'];

  require_once(ABSPATH . 'wp-admin/includes/file.php');
  require_once(ABSPATH . 'wp-admin/includes/media.php');
  require_once(ABSPATH . 'wp-admin/includes/image.php');
  $attach_id = tcb_media_sideload_image( $picurl, $postarr['ID'] );  //
Same as core but return post_id

  update_post_meta( $postarr['ID'], 'supplier_picture', $attach_id );
}


On 14 November 2012 16:15, Mike Bijon <mike at etchsoftware.com> wrote:

> Tom,
> There are some simple ways to include a file upload text box on the
> frontend,
>
> http://goldenapplesdesign.com/2010/07/03/front-end-file-uploads-in-wordpress/
>
> You can also look at plugins named various versions of " frontend upload"
> to see different ways of queueing media for reviews, custom upload folders,
> etc.
>
> If you really want to use drag-and-drop or multi-uploading everything I've
> seen uses a duplicate Pluploader instead of hooking the built-in one,
> http://designmodo.com/create-upload-form/. It should be possible to use
> the
> back end one but I don't know about the security of that.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett


More information about the wp-hackers mailing list