Leave a Reply

3 comments

  1. Again. If you are using file upload, it is different than image upload. To get a FILE url, use: $(html).attr(‘href’);

    File upload:

    window.send_to_editor = function(html){
        var file_url = $(html).attr('href');
    
        // Do something with those variables
    
        tb_remove();
    };
    

    Image upload:

    window.send_to_editor = function(html){
        var file_url = $('img', html).attr('src'),
            classes  = $('img', html).attr('class'),
            id       = classes.replace(/(.*?)wp-image-/, '');
    
        // Do something with those variables
    
        tb_remove();
    };
    
  2. try this:

    window.send_to_editor = function(html){
        dlink = jQuery('img',html).attr('src');
        jQuery('#download_link').val(dlink);
        tb_remove();
    }
    
  3. <div>
        <label style="float:left; margin: 5px 5px 0 0;">Image 4:</label>
        <input type="text" id="image_4" name="image_4" value="" style="width: 550px; float:left; margin:0 5px;"/>
        <input id="_btn" class="upload_image_button" type="button" value="Upload Image" />
        <input type="hidden" name="image4_id" id="image4_id" value="<?php echo $image_id4; ?>" />
    </div>
    
    <script>
    jQuery(document).ready(function () {
        var formfield;
        var id;
        jQuery('.upload_image_button').click(function () {
            jQuery('html').addClass('Image');
            formfield = jQuery(this).prev().attr('name');
            id = jQuery(this).next().attr('name');
    
            tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
            return false;
        });
        window.original_send_to_editor = window.send_to_editor;
        window.send_to_editor = function (html) {
            if (formfield) {
                fileurl = jQuery('img', html).attr('src');
                jQuery('#' + formfield).val(fileurl);
    
                imgclass = jQuery('img', html).attr('class');
                imgid = parseInt(imgclass.replace(/D/g, ''), 10);
                jQuery('#' + id).val(imgid);
    
                tb_remove();
                jQuery('html').removeClass('Image');
            } else {
                window.original_send_to_editor(html);
            }
        };
    });
    </script>