admin管理员组文章数量:1316204
I want to upload files from direct directory. But in my codes it will open media library then select files to upload
jQuery('#t_pdf').on("click", function(){
// alert("got it");
var image = wp.media({
title: "Upload PDF for Assignments",
multiple: false
}).open().on("select",function(){
var uploaded_image = image.state().get("selection").first();
var getpdf = uploaded_image.toJSON().url;
jQuery("#show-pdf").html("<a class='btn btn-success' target='_blank' href='"+getpdf+"'>View PDF</a>");
jQuery("#sub_file_pdf").val(getpdf);
});
});
When I click button
<input type="button" class="btn btn-info" id="t_pdf" value="Upload File" required>
<span id="show-pdf"></span>
<input type="hidden" id="sub_file_pdf" name="sub_file">
it will follow the script and open media library, want to upload files from direct files directory and upload it to specific custom folder.
Can anyone help me to find out this?
I want to upload files from direct directory. But in my codes it will open media library then select files to upload
jQuery('#t_pdf').on("click", function(){
// alert("got it");
var image = wp.media({
title: "Upload PDF for Assignments",
multiple: false
}).open().on("select",function(){
var uploaded_image = image.state().get("selection").first();
var getpdf = uploaded_image.toJSON().url;
jQuery("#show-pdf").html("<a class='btn btn-success' target='_blank' href='"+getpdf+"'>View PDF</a>");
jQuery("#sub_file_pdf").val(getpdf);
});
});
When I click button
<input type="button" class="btn btn-info" id="t_pdf" value="Upload File" required>
<span id="show-pdf"></span>
<input type="hidden" id="sub_file_pdf" name="sub_file">
it will follow the script and open media library, want to upload files from direct files directory and upload it to specific custom folder.
Can anyone help me to find out this?
Share Improve this question asked Oct 19, 2020 at 17:32 ShawnShawn 11710 bronze badges1 Answer
Reset to default 0I fix this problems with wordpress file upload method:
php file:
add_action( 'wp_ajax_file_upload', 'file_upload_callbacks' );
add_action( 'wp_ajax_nopriv_file_upload', 'file_upload_callbacks' );
function file_upload_callbacks() {
$arr_img_ext = array('application/pdf');
if (in_array($_FILES['file']['type'], $arr_img_ext)) {
$upload = wp_upload_bits($_FILES["file"]["name"], null, file_get_contents($_FILES["file"]["tmp_name"]));
//$upload['url'] will gives you uploaded file path
//var_dump($upload['url']);
wp_send_json( $upload['url'] );
}
wp_die();
}
本文标签: jquerywordpress file upload from direct directory not working
版权声明:本文标题:jquery - wordpress file upload from direct directory not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741976810a2408172.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论