[wp-hackers] Handle Image Upload via jQuery .post?

BenderisGreat greglancaster71 at gmail.com
Tue Nov 5 03:21:58 UTC 2013


converting a form to ajax, and I currently have file uploads being handles
like so:

function insert_attachment($file_handler,$post_id,$setthumb='false') {
	if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK){return
__return_false(); }
 	require_once(ABSPATH . "wp-admin" . '/includes/image.php');
	require_once(ABSPATH . "wp-admin" . '/includes/file.php');
	require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$attach_id = media_handle_upload( $file_handler, $post_id );
 
  if ($setthumb) update_post_meta($post_id,'_thumbnail_id',$attach_id);
  return $attach_id;

}

Then in the form, I am using:


	foreach ($_FILES as $file => $array) 
	{
	$newupload = insert_attachment($file,$post_id); 
	}

This returns uploads the image and returns the attachment id for placement
in a db table.  After converting to ajax, this function no longer works.  

Any possible way to run the insert_attachment function on click only, and
then run the ajax post submit?  Or obviously the better solution would be to
handle it all from the action call function.  






--
View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/Handle-Image-Upload-via-jQuery-post-tp42717.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.


More information about the wp-hackers mailing list