• i have images uploaded from ftp to my site i want to integrate it to my media library , i find code to do though but problem is that my file names is in Arabic
    when i use this code it convert all my names to ???
    is there any way t do that right??
    i used rawurlencode() for post_title and it is ok but in post_name no and generated images also named ???
    this is the code

    <?php
    
    // $filename should be the path to a file in the upload directory.
    $filename = '/path/to/uploads/2013/03/???-??????.jpg';
    $name=rawurlencode(basename( $filename ));
    // The ID of the post this attachment is for.
    $parent_post_id = 37;
    
    // Check the type of tile. We'll use this as the 'post_mime_type'.
    $filetype = wp_check_filetype( basename( $filename ), null );
    
    // Get the path to the upload directory.
    $wp_upload_dir = wp_upload_dir();
    
    // Prepare an array of post data for the attachment.
    $attachment = array(
    	'guid'           => $wp_upload_dir['url'] . '/' . basename( $filename ),
    	'post_mime_type' => $filetype['type'],
    	'post_title'     => $name,
    	'post_content'   => '',
    	'post_status'    => 'inherit'
    );
    
    // Insert the attachment.
    $attach_id = wp_insert_attachment( $attachment, $filename, $parent_post_id );
    
    // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
    require_once( ABSPATH . 'wp-admin/includes/image.php' );
    
    // Generate the metadata for the attachment, and update the database record.
    $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
    wp_update_attachment_metadata( $attach_id, $attach_data );

  • The topic ‘unicode images file names’ is closed to new replies.