admin管理员组文章数量:1325581
i am using this query in my plugin to uploading media file , when i keep it file in wp_enqueue_script it working properly except after i select the image , this code does not return on wordpress page.
$content .='<div class="col-sm-6">';
$content .='<label class="fo">Upload Image</label>';
$content .='<input type="button" type="button" name="txt_image"id="txt_image" class="form-control"style=" font: italic bold 12px/30px Georgia, serif;font-size:20px;" value="Upload Image">';
$content .='<img src="" id="getImage" style="height:100px;width:100px;"/>';
$content .='<input type="hidden" name="student_image" id="student_image"/>';
$content .='</div>';
<script>
jQuery(document).on("click","#txt_image",function(){
var image = wp.media({
title:"Upload Image",
multiple:false
}).open().on("select", function(e){
var uploaded_image = image.state().get("selection").first();
var image_data = uploaded_image.toJSON();
jQuery("#getImage").attr("src", image_data.url);
jQuery("#student_image").val(image_data.url);
});
});
</script>
i am using this query in my plugin to uploading media file , when i keep it file in wp_enqueue_script it working properly except after i select the image , this code does not return on wordpress page.
$content .='<div class="col-sm-6">';
$content .='<label class="fo">Upload Image</label>';
$content .='<input type="button" type="button" name="txt_image"id="txt_image" class="form-control"style=" font: italic bold 12px/30px Georgia, serif;font-size:20px;" value="Upload Image">';
$content .='<img src="" id="getImage" style="height:100px;width:100px;"/>';
$content .='<input type="hidden" name="student_image" id="student_image"/>';
$content .='</div>';
<script>
jQuery(document).on("click","#txt_image",function(){
var image = wp.media({
title:"Upload Image",
multiple:false
}).open().on("select", function(e){
var uploaded_image = image.state().get("selection").first();
var image_data = uploaded_image.toJSON();
jQuery("#getImage").attr("src", image_data.url);
jQuery("#student_image").val(image_data.url);
});
});
</script>
Share
Improve this question
edited Aug 11, 2020 at 19:34
t2pe
4823 silver badges11 bronze badges
asked Aug 11, 2020 at 10:41
Arshpreet VenveruArshpreet Venveru
94 bronze badges
1
- Do it the wordpress codex way not with jQuery as you need the theme and php code to be aware of your file: premium.wpmudev/blog/upload-file-functions. – Nathaniel Flick Commented Aug 11, 2020 at 20:49
1 Answer
Reset to default 0jQuery(document).ready(function($){
$('#txt_image').click (function(e){
e.preventDefault();
var image = wp.media({
title:"Upload Image",
multiple:false
}).open().on("select", function(e){
var uploaded_image = image.state().get("selection").first();
var image_data = uploaded_image.toJSON();
jQuery("#getImage").attr("src", image_data.url);
jQuery("#student_image").val(image_data.url);
});
});
});
本文标签: uploadsmedia file uploading
版权声明:本文标题:uploads - media file uploading 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742190075a2430048.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论