• Hi, I have a registration form that includes an image upload as well. Now the image uploading works 100%, its when I try to “edit image” in the backend where things break. Images that are uploaded via the client facing side, when I edit them and crop them smaller, and save it the file name changes but the image is broken and can not be found. However images uploaded from the backend directly into the media section, when cropped work 100%. Here is my client side image uploading 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'] ,$attach_post_id);
    
    					// generate the attachment metadata
    					$attach_data = wp_generate_attachment_metadata( $attachment_id, $uploaded_file['file'] );
    
    					wp_update_attachment_metadata( $attachment_id,  $attach_data );
    					set_post_thumbnail( $attach_post_id, $attachment_id );
    				}
  • The topic ‘Custom client side media uploads and editing’ is closed to new replies.