0
프로그래밍 방식으로 프런트 엔드에서 비디오를 업로드하려고합니다. 프로그래밍 방식으로 프런트 엔드에서 비디오 업로드 Wordpress
이
내 코드입니다 :<?php
if (isset($_POST['uploadvideo'])) {
if (! function_exists('wp_handle_upload')) {
require_once(ABSPATH . 'wp-admin/includes/image.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/media.php');
}
$uploadedfile = $_FILES['photoContent'];
$upload_overrides = array('test_form' => false);
$movefile = wp_handle_upload($uploadedfile, $upload_overrides);
if ($movefile)
{
$image_url = $movefile["url"];
$upload_dir = wp_upload_dir();
$image_data = file_get_contents($image_url);
$filename = basename($image_url);
if(wp_mkdir_p($upload_dir['path']))
$file = $upload_dir['path'] . '/' . $filename;
else
$file = $upload_dir['basedir'] . '/' . $filename;
file_put_contents($file, $image_data);
$wp_filetype = wp_check_filetype($filename, null);
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name($filename),
'post_content' => '',
'post_status' => 'inherit'
);
$listing_post_id = 780 ; // post id
$attach_id = wp_insert_attachment($attachment, $file, $listing_post_id);
$attach_data = wp_generate_attachment_metadata($attach_id, $file);
wp_update_attachment_metadata($attach_id, $attach_data);
/*end file uploader*/
}
}
?>
<form method ="post" action="" name="uploadvideo" enctype="multipart/form-data">
<label for="ug_photo">Your Video Files
<input type="file" value="" name="photoContent" id="ug_photo" class="" multiple="multiple"></label>
<label for="ug_submit_button">
<input type="submit" value="uploadvideo" name="uploadvideo" id="ug_submit_button" class="btn"></label>
</form>
그러나 그것은 작동하지 않습니다. 게시물 ID 780을 하드 코드했습니다. 나중에 변경할 예정입니다.
도와주세요. 미리 감사드립니다.
부패 란 무엇입니까? 어떤 오류를보고 있는지 설명해 주시겠습니까? – krishna89
@ krishna89 아무런 오류 메시지가 나타나지 않습니다. 업로드하지 않습니다. 질문을 수정했습니다. –
오류보고를 켜거나 웹 서버의 오류 로그를보십시오. 실제 오류 메시지가 없으면 문제가 무엇인지 추측하기가 불가능합니다. –