Client Side Media Uploader Not Working
-
Hi, When uploading images from the frontend of the site, then editing them in the backend example – croping them, the cropped image is not generated on the server. However when I upload the image via the CMS it then edit it, it works 100%…
Here is my code for the upload functionality, is there a setting and or param that I am missing?
if(isset($_FILES['file']['name'])){ $upload_overrides = array( 'test_form' => FALSE ); require $_SERVER['DOCUMENT_ROOT'] . "/wp-admin/includes/file.php"; require $_SERVER['DOCUMENT_ROOT'] . "/wp-admin/includes/image.php"; $file_array = array( 'name' => $_FILES['file']['name'], 'type' => $_FILES['file']['type'], 'tmp_name' => $_FILES['file']['tmp_name'], 'error' => $_FILES['file']['error'], 'size' => $_FILES['file']['size'] ); if ( !empty( $file_array['name'] ) ) { $uploaded_file = wp_handle_upload( $file_array, $upload_overrides ); $wp_filetype = wp_check_filetype( basename( $uploaded_file['file'] ), NULL ); $wp_upload_dir = wp_upload_dir(); // set up the array of arguments for "wp_insert_post();" $attachment = array( 'guid' => $wp_upload_dir['url'] . '/' . basename( $uploaded_file['file'] ), 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', basename($uploaded_file['file'])), 'post_content' => '', 'post_status' => 'inherit' ); $attachment_id = wp_insert_attachment( $attachment, $wp_upload_dir['subdir'] .'/'. $file_array['name'] ,2); // generate the attachment metadata print_r($uploaded_file); $attach_data = wp_generate_attachment_metadata( $attachment_id, $uploaded_file['file'] ); wp_update_attachment_metadata( $attachment_id, $attach_data ); } }
- The topic ‘Client Side Media Uploader Not Working’ is closed to new replies.