반응형
민첩한 업로더 워드프레스 구현
저는 사용자에게 워드프레스 페이지에서 이미지를 업로드할 수 있는 권한을 부여하고 업로드 전에 이미지 크기를 조정하는 전면 워드프레스 업로더를 구현하려고 합니다.애자일 업로더를 찾았습니다업로더가 양식에 있습니다.
문제는 자료를 보내려고 양식에 있는 제출 버튼을 클릭하면 모든 필드가 게시물에 저장되지만 이미지는 그렇지 않습니다.
업로드 페이지 코드는 다음과 같습니다.
<form id="submitForm" action="<?php echo get_permalink(); ?>" method="post" enctype="multipart/form-data" onsubmit="return ray.ajax()">
<!-- upload photos -->
<div style="float:left;width:410px; height:246px;">
<div id="multiple"></div>
</div>
<script type="text/javascript">
jQuery('#multiple').agileUploader({
formId: 'submitForm',
flashVars: {
file_post_var: 'attachment',
firebug: false,
form_action: '',
file_limit: 15,
max_post_size: (1000 * 1024)
}
});
</script>
</div> <!-- end - upload photos -->
</form>
워드프레스 업로드 코드 (같은 파일에 있음)
/* upload photos */
if ($post_error == false) {
/* required files */
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$files = $_FILES['attachment'];
if ($files) {
foreach ($files['name'] as $key => $value) {
if ($files['name'][$key]) {
$file = array(
'name' => $files['name'][$key],
'type' => $files['type'][$key],
'tmp_name' => $files['tmp_name'][$key],
'error' => $files['error'][$key],
'size' => $files['size'][$key]
);
}
$_FILES = array("attachment" => $file);
//$_FILES = array_reverse($_FILES);
foreach ($_FILES as $file => $array) {
$attach_id = media_handle_upload( $file, $ad_id, array(), array( 'test_form' => false ) );
if ($attach_id < 0) { $post_error = true;
}
}
}
}
내가 뭘 잘못하고 있는 거지?
작성한 게시물에 이미지가 '첨부'로 저장되지 않아도 됩니까?
실행 시도:
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id())
);
var_dump($attachments);
게시물을 볼 때 사용하는 템플릿 파일.코딩이 불편한 경우 플러그인을 사용하여 첨부 파일을 표시할 수 있습니다.이 "List Attachments Shortcode" 플러그인처럼.
이것은 조금 간단할 수도 있고, 문제가 아닐 수도 있지만, 여러분은 곱슬곱슬한 중괄호 끝을 놓치고 있습니다. (}
)후에if ($attach_id < 0) { $post_error = true;
.
그것이 당신의 실제 코드에 있는 것입니까 아니면 단지 위의 질문에 그것을 넣는 것을 잊어버린 것입니까?
언급URL : https://stackoverflow.com/questions/13840906/agile-uploader-wordpress-implementation
반응형
'programing' 카테고리의 다른 글
구글 애널리틱스로 IF 프레임에서 클릭을 추적하는 방법? (0) | 2023.10.29 |
---|---|
PowerShell로 특정 이름의 폴더를 재귀적으로 삭제하려면 어떻게 해야 합니까? (0) | 2023.10.29 |
자바스크립트를 통해 CSS 사용자 지정 속성(일명 CSS 변수) 접근 (0) | 2023.10.29 |
UI 글꼴 - 시스템 얇은 글꼴을 가져오는 방법 (0) | 2023.10.29 |
뒤로 가기 단추에서 텍스트를 변경하는 방법 (0) | 2023.10.29 |