文件操作 - forms.php
返回文件管理
返回主菜单
删除本文件
文件: /var/www/ltlcompare.com/wp-content/themes/ltl-compare/functions/forms.php
编辑文件内容
<?php // add_action( 'wp_ajax_nopriv_ltl_compare_form_action', 'ltl_compare_form_action' ); // add_action( 'wp_ajax_ltl_compare_form_action', 'ltl_compare_form_action' ); function ltl_compare_form_action() { if ( empty( $_POST ) || ! wp_verify_nonce( $_POST['ajax_nonce_field'], 'ajax') ) { exit(); } $fields = array( 'name' => __( 'Name', DOMAIN ), 'tel' => __( 'Phone', DOMAIN ), ); $values = array(); foreach ( $fields as $key => $item ) { $values[$key] = sanitize_text_field( $_POST[$key] ); } $files = $_FILES; $attachments = array(); $file_links = ''; $file_urls = array(); if ( count( $files ) ) { foreach ( $files as $key => $file ) { $file_name = basename( $file['name'] ); if ( $file_name ) { $folder = TEMPLATEPATH . '/files'; if ( ! file_exists( $folder ) ) { mkdir( $folder, 0777, true ); } $file_name = explode( '.', $file_name ); $file_name = $file_name[0] . '_' . time() . '.' . $file_name[count( $file_name ) - 1]; $file_path = $folder . '/' . $file_name; $f = move_uploaded_file( $file['tmp_name'], $file_path ); $attachments[] = $file_path; $file_url = TEMPLATE_URL . '/files/' . $file_name; $file_urls[$key] = $file_url; $file_links .= '<a href="' . $file_url . '" download>' . $file['name'] . '</a>'; } } } $headers = array( 'From: <' . get_bloginfo( 'admin_email' ) . '>', 'Content-Type: text/html', ); $title = sanitize_text_field( $_POST['title'] ) ?: __( 'New application', DOMAIN ); $subject = $title; if ( $title ) { $msg .= '<p><b>' . __( 'Subject', DOMAIN ) . ':</b> ' . $title . '</p>'; } foreach ( $values as $key => $item ) { if ( $item ) { $msg .= '<p><b>' . $fields[$key] . ':</b> ' . $item . '</p>'; } } if ( $file_links ) { $msg .= '<p><b>' . __( 'Files', DOMAIN ) . ': </b> ' . $file_links . '</p>'; } if ( $_SERVER['REMOTE_ADDR'] ) { $msg .= '<p><b>REMOTE_ADDR:</b> ' . $_SERVER['REMOTE_ADDR'] . '</p>'; } if ( $_SERVER['HTTP_REFERER'] ) { $msg .= '<p><b>HTTP_REFERER:</b> <a href="' . $_SERVER['HTTP_REFERER'] . '" target="_blank">' . $_SERVER['HTTP_REFERER'] . '</a></p>'; } remove_filter( 'wp_mail_from', 'custom_wp_mail_from' ); $send_to = get_bloginfo( 'admin_email' ); if ( $values['tel'] ) { $m = wp_mail( $send_to, $subject, $msg, $headers, $attachments ); if ( $m ) { echo 'ok'; } } exit(); } ?>
修改文件时间
将文件时间修改为当前时间的前一年
删除文件