2014-06-20 9 views
0

파일 업로드를 WordPress에 추가하려고하면 move_uploaded_file을 제외한 모든 기능이 제대로 작동합니다.WordPress에 문제가있는 Move_uploaded_file

<input type="file" name="attachment" id="attachment"> 

if (!move_uploaded_file($_FILES["attachment"]["tmp_name"],WP_CONTENT_DIR .'/uploads/cv/'.basename($_FILES['attachment']['name']))) 
     { 
      $return['error'] = true; $return['error_message'] = __('File could not be uploaded', 'btoa').'<br />'; 

     } 

업로드 된 파일을 이동하려고 위의 제 형태의 필드는 작업 및 오류를 표시하지 않는 것.

나는 또한 false를 반환하는 is_uploaded_file 사용하려고했습니다의 업로드 폴더는 777, 그것은하려고하는 폴더에 내가 무슨 일이 일어나고 있는지 확실히 모르겠습니다/이력서 /도 777

입니다에 저장 여기에 오류 로그가 생성되지 않고 그냥 작동하지 않는 것 같습니다.

업로드 된 파일을 이동하는 것 외에도 첨부 파일을 보내는 작업은 완벽하게 작동합니다.

내가 할 수있는 것은 무엇입니까? 이 버그를 수정하는 동안

FORM 코드

<form action="<?php echo home_url() ?>" method="post" id="enquiry-form" enctype="multipart/form-data"> 

      <p><small class="error" style="margin-top: 15px; display: none;"></small></p> 

      <p><input type="text" value="<?php _e('Your name', 'btoa'); ?>" name="name" id="enquiry-name" onfocus="if(jQuery(this).val() == '<?php _e('Your name', 'btoa'); ?>') { jQuery(this).val(''); }" onblur="if(jQuery(this).val() == '') { jQuery(this).val('<?php _e('Your name', 'btoa'); ?>'); }" /></p> 

      <p><input type="text" value="<?php _e('Email address', 'btoa'); ?>" name="email" id="enquiry-email" onfocus="if(jQuery(this).val() == '<?php _e('Email address', 'btoa'); ?>') { jQuery(this).val(''); }" onblur="if(jQuery(this).val() == '') { jQuery(this).val('<?php _e('Email address', 'btoa'); ?>'); }" /></p> 
      <p><label for="file">Upload your CV/Resume:</label></p> 
      <p style="margin-bottom:0;"><input type="file" name="attachment" id="attachment"></p> 

      <p><textarea name="message" id="enquiry-message" cols="" rows="4" onfocus="if(jQuery(this).val() == '<?php _e('Message', 'btoa'); ?>') { jQuery(this).val(''); }" onblur="if(jQuery(this).val() == '') { jQuery(this).val('<?php _e('Message', 'btoa'); ?>'); }"><?php _e('Message', 'btoa'); ?></textarea></p> 

      <p><input type="submit" class="button-primary" value="<?php _e('Send', 'btoa'); ?>" /></p> 

      <div class="clear"></div> 
      <!-- /.clear/ --> 

      <div class="error-message"></div> 

      <div class="thank-you hidden"> 

       <p><?php _e('Thank you! Your message has been successfully sent.', 'btoa'); ?></p> 

      </div> 

     </form> 

성공 FORM 코드

//// IF EMAIL IS VALID 
    if($return['error'] == '') { 

     /// GETS OTHER VARS 
     $name = isset($_POST['email']) ? trim($_POST['name']) : ''; 
     $the_message = isset($_POST['message']) ? trim($_POST['message']) : ''; 
     $post_id = isset($_POST['post_id']) ? trim($_POST['post_id']) : ''; 

     //// NOW WE GET OUR SPOT AND THE USER 
     $spot = get_post($post_id); 
     $user = get_user_by('id', $spot->post_author); 

     //// STARTS OUR RECIPIENT ARRAY 
     $to = $user->user_email; 

     //// HEADERS 
     $headers = 'From: '.get_bloginfo('name').' <'.get_option('admin_email').'>'."\r\n". 
     'Reply-To: '.$email; 

     $subject = sprintf2(__('%site_name Contact: %spot_name', 'btoa'), array('site_name' => get_bloginfo('name'), 'spot_name' => $spot->post_title)); 
     if (!move_uploaded_file($_FILES["attachment"]["tmp_name"],WP_CONTENT_DIR .'/uploads/cv/'.basename($_FILES['attachment']['name']))) 
     { 
      $return['error'] = true; $return['error_message'] = __('File could not be uploaded', 'btoa').'<br />'; 
      error_reporting(E_ERROR | E_WARNING | E_PARSE); 

     } 


$attachments = array(WP_CONTENT_DIR ."/uploads/cv/".basename($_FILES['attachment']['name'])); 
     add_filter('wp_mail_content_type', 'my_custom_email_content_type'); 
     function my_custom_email_content_type() { 
return 'text/html'; 
} 
     $message = sprintf2(__("Dear %author, 

%user (email: %email) has sent you a message via %site_name: 

----- 

%message", 'btoa'), array(

      'author' => $user->display_name, 
      'user' => $name, 
      'email' => $email, 
      'site_name' => get_bloginfo('name'), 
      'attachment' => $attachments, 
      'message' => $the_message 

     )); 



     //// SENDS OUT OUR EMAIL 
     if(!wp_mail($to, $subject, stripslashes($message), $headers, $attachments)) { 

      $return['error'] = true; $return['error_email'] = sprintf2(__('There was a problem sending your enquiry. Please email us directly at %site_email', 'btoa'), array('site_email' => get_option('admin_email'))); 

     } else { $return['success'] = stripslashes($headers); } 

    } 

    echo json_encode($return); 
    exit; 

} 

는 약간 지저분한 코드를 무시합니다.

또한이 wp_config에 조정/추가하려고 시도하지만, 여전히 오류 로그는

// Enable WP_DEBUG mode 
define('WP_DEBUG', true); 

// Enable Debug logging to the /wp-content/debug.log file 
define('WP_DEBUG_LOG', true); 

// Disable display of errors and warnings 
define('WP_DEBUG_DISPLAY', false); 
@ini_set('display_errors',0); 

// Use dev versions of core JS and CSS files (only needed if you are modifying these core files) 
define('SCRIPT_DEBUG', true); 
+0

오류 로그를받습니다. – Ranjith

+0

고마워요, 그래도 끝났지 만 error_log가 생성되지 않았으므로 이것을 디버깅하는 방법이 확실하지 않아보다 완전한 코드를 게시 할 수 있습니다. . – Jamie000012

답변

0

당신이 WP_CONTENT_DIR에서 울리는 그 가져 무엇을보고 시도 되세요 루트 또는 WP - 콘텐츠 생성되고 있지? 또는 var_dump(is_dir(WP_CONTENT_DIR .'/uploads/cv/'.basename($_FILES['attachment']['name']))을 수행하고 있습니다. 또한 $ _FILES 배열에서 print_r을 수행하여 반환하는 실제 오류 번호를 확인하고 그 값을 다음과 연결하십시오 : http://us1.php.net//manual/en/features.file-upload.errors.php. 당연히 알아낼 수 없다면 각자에게 결과를 알려주세요.