Wednesday, 15 September 2010

php - Move_uploaded_file having issues with WordPress -



php - Move_uploaded_file having issues with WordPress -

trying add together file upload wordpress, working far except move_uploaded_file.

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

the field in form above

if (!move_uploaded_file($_files["attachment"]["tmp_name"],wp_content_dir .'/uploads/cv/'.basename($_files['attachment']['name']))) { $return['error'] = true; $return['error_message'] = __('file not uploaded', 'btoa').'<br />'; }

attempting move uploaded file, it's not working , displaying error.

i've tried utilize is_uploaded_file, returns false, uploads folder 777, folder trying save in /cv/ 777.

i not quite sure going wrong here, there no error log beingness created , can't seem work.

apart moving uploaded file, sending out attachments working perfectly.

anything can do?

form code

<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 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! message has been sent.', 'btoa'); ?></p> </div> </form>

success form code

//// if email 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']) : ''; //// our spot , 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 not 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() { homecoming 'text/html'; } $message = sprintf2(__("dear %author, %user (email: %email) has sent 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 problem sending enquiry. please email straight @ %site_email', 'btoa'), array('site_email' => get_option('admin_email'))); } else { $return['success'] = stripslashes($headers); } } echo json_encode($return); exit; }

ignore messy code while trying prepare bug.

also attempted add/adjust in wp_config, still no error logs beingness created in root or wp-content

// enable wp_debug mode define('wp_debug', true); // enable debug logging /wp-content/debug.log file define('wp_debug_log', true); // disable display of errors , warnings define('wp_debug_display', false); @ini_set('display_errors',0); // utilize dev versions of core js , css files (only needed if modifying these core files) define('script_debug', true);

have tried echoing out wp_content_dir , seeing gets? or doing var_dump(is_dir(wp_content_dir .'/uploads/cv/'.basename($_files['attachment']['name'])). doing print_r on $_files array see actual error number returns , correlating with: http://us1.php.net//manual/en/features.file-upload.errors.php may help. allow me know results each please unless of course of study figure out.

php wordpress

No comments:

Post a Comment