It works (upload , send to db) but
wp_generate_attachment_metadata()
returns bad letters whene file uploaded !
some of the wrong charechters :
����JFIF��;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 90 ��C ��C ����"�� ���}!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������� ���w!1AQaq"2�B���� #3R�br� $4�
the code :
if (isset($_FILES['ed_header_logo'] ) && !empty($_FILES['ed_header_logo']['name']) )
{
$filename = $_FILES['ed_header_logo']['name'];
$wp_filetype = wp_check_filetype( basename($filename), null );
$wp_upload_dir = wp_upload_dir();
move_uploaded_file( $_FILES['ed_header_logo']['tmp_name'], $wp_upload_dir['path'] . '/' . $filename );
$url = $wp_upload_dir['url'] . '/' . basename( $filename );
$attachment = array(
'guid' => $url,
'post_mime_type' => $wp_filetype['type'],
'post_title' => preg_replace( '/.[^.]+$/', '', basename( $filename ) ),
'post_content' => 'weblogo',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $url, 37 );
require_once( ABSPATH . 'wp-admin/includes/image.php' );
$attach_data = wp_generate_attachment_metadata( $attach_id, $url );
wp_update_attachment_metadata( $attach_id, $attach_data );
}
try this: