programing

민첩한 업로더 워드프레스 구현

codeshow 2023. 10. 29. 20:04
반응형

민첩한 업로더 워드프레스 구현

저는 사용자에게 워드프레스 페이지에서 이미지를 업로드할 수 있는 권한을 부여하고 업로드 전에 이미지 크기를 조정하는 전면 워드프레스 업로더를 구현하려고 합니다.애자일 업로더를 찾았습니다업로더가 양식에 있습니다.

문제는 자료를 보내려고 양식에 있는 제출 버튼을 클릭하면 모든 필드가 게시물에 저장되지만 이미지는 그렇지 않습니다.

업로드 페이지 코드는 다음과 같습니다.

<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

반응형