duanmengmiezen8855 2016-06-23 16:40
浏览 31

提交前使用输入。 上传PDF时生成文件名

I'm trying to adjust my plugin a bit. I'd like to change the file name of an upload as I'm adding a new product. My current solutions - I've disabled the tb_show image upload box from appearing if the name input has not been filled out. This way we'll have that value. In my init.php file I have this which seems to be what I'm looking for. A way to edit the file name :

add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );

    function custom_upload_filter( $file ){

            $fileNameHere = $_POST["bv_product_num"];
            $file['name'] = 'new value';
                //return $files;
                exit(var_dump($fileNameHere));
        $fileNameHere = $_POST["bv_product"];

    }

in my create.php file which is for the user I have :

<script type="text/javascript">
        //tb_show('', 'media-upload.php?TB_iframe=true');


        /*----------------------------------------------*/

        jQuery(document).ready(function() {

        jQuery('.upload_image_button').click(function() {

            original_send_to_editor = window.send_to_editor;
            window.send_to_editor = function(html) {
                hrefurl = jQuery(html).attr('href');
                jQuery('#'+formfieldID).val(hrefurl);
                tb_remove(); 
                window.send_to_editor = original_send_to_editor;
            }
            // loads thickbox
            upload_image_button =true;
            formfieldID=jQuery(this).prev().attr("id");
            formfield = jQuery("#"+formfieldID).attr('name');
            /*
            * Get values of above boxes
            */
            //bv_product_num=jQuery('#bv_product_num').val();
            bv_product_num=jQuery('#bv_product_num').val();
            bv_product_num="this";
            bv_product_iw_bulk=jQuery('#bv_product_iw_bulk').val();
            bv_wg_lf_rf=jQuery('#bv_wg_lf_rf').val();//not necessary str.replace(',','.').replace(' ','')
            bv_product_name=jQuery('#bv_product_name').val();
            bv_pack_oz=jQuery('#bv_pack_oz').val();
            fileNameHere = bv_product_num+"_"+bv_wg_lf_rf+"_"+bv_product_name+"_"+bv_pack_oz+"_oz";
            //if(bv_product_num && bv_product_iw_bulk && bv_wg_lf_rf && bv_product_name && bv_pack_oz)
            if(bv_product_num)
            {
                /*-------------------------
        ----------------------------
        ------------------------------
        ------------------------------
        ----------------------------
        ------------------------------
        */



        /*------------------------------------------------
        -------------------------------------------------
        --------------------------------------------------
        --------------------------------------------------
        ------------------------------------------------*/
                tb_show('', 'media-upload.php?bv_product=+'+fileNameHere+'&type=image&amp;TB_iframe=true');
                return false;


            }else{          
            alert("nothing");
            }
            //formfield = jQuery("#"+formfieldID).attr('name');
            /**/

        });


        })

        //old----------------------------------

        /*jQuery(document).ready(function() {

        jQuery('.upload_image_button').click(function() {
            original_send_to_editor = window.send_to_editor;
                window.send_to_editor = function(html) {
                hrefurl = jQuery(html).attr('href');
                jQuery('#'+formfieldID).val(hrefurl);
                tb_remove(); 
                window.send_to_editor = original_send_to_editor;
                }
         loads thickbox
        upload_image_button =true;
            formfieldID=jQuery(this).prev().attr("id");
         formfield = jQuery("#"+formfieldID).attr('name');
        tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
        return false;
        });


        })*/

    </script>

What I'm trying to do is pass the variables from my main plugin page to my init file so that I can manipulate them. What is the correct flow for communicating these variables in this way?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题