GVKun编程网logo

PHP图像上传(WordPress自定义插件)(php图片上传插件)

24

如果您想了解PHP图像上传(WordPress自定义插件)和php图片上传插件的知识,那么本篇文章将是您的不二之选。我们将深入剖析PHP图像上传(WordPress自定义插件)的各个方面,并为您解答p

如果您想了解PHP图像上传(WordPress自定义插件)php图片上传插件的知识,那么本篇文章将是您的不二之选。我们将深入剖析PHP图像上传(WordPress自定义插件)的各个方面,并为您解答php图片上传插件的疑在这篇文章中,我们将为您介绍PHP图像上传(WordPress自定义插件)的相关知识,同时也会详细的解释php图片上传插件的运用方法,并给出实际的案例分析,希望能帮助到您!

本文目录一览:

PHP图像上传(WordPress自定义插件)(php图片上传插件)

PHP图像上传(WordPress自定义插件)(php图片上传插件)

我有一个正在使用的wordpress插件,似乎遇到了问题.
我需要用户能够上传图片,但我一直遇到这个问题:

上载目录不可写或不存在.

Warning:
move_uploaded_file(http://markpetherbridge.co.uk/ios/wp-content/plugins/rap/includes/productimages/78.105.162.431328735863.png)
[function.move-uploaded-file]: Failed to open stream: HTTP wrapper
does not support writeable connections in
/home/markpeth/public_html/ios/wp-content/plugins/rap/includes/products.PHP
on line 39

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to
move ‘/tmp/PHPowqMlu’ to
‘http://markpetherbridge.co.uk/ios/wp-content/plugins/rap/includes/productimages/78.105.162.431328735863.png’
in
/home/markpeth/public_html/ios/wp-content/plugins/rap/includes/products.PHP
on line 39 There was an error uploading the file, please try again!
You have successfully added test_title to your products list

该目录绝对存在,我什至将CHMOD更改为777进行测试.

products.PHP文件如下所示:

 <?
if ('POST' == $_SERVER['REQUEST_METHOD'])
 {
global $wpdb;

$product_title = $_POST['title'];
$product_url = $_POST['url'];
$product_btn_text = $_POST['btn_text'];

// CREATE UNIQUE NAME FOR IMAGE
$remote_addr = $_SERVER['REMOTE_ADDR'];
$time = time();
$new_name = $remote_addr;
$new_name .= $time;


// IMAGE UPLOAD

$upload_dir = "http://markpetherbridge.co.uk/ios/wp-content/plugins/rap/includes/productimages/"; 

if (file_exists($upload_dir) && is_writable($upload_dir)) {
        echo "<br /> Directory exists and is fine.... <br />";
}
else {
        echo "Upload directory is not writable, or does not exist. <br />";
}

$uploadedfile = $_FILES['image_file']['name'];
$extension = explode(".", $uploadedfile);
$extensiontype = $extension['1'];

$target_path = $upload_dir;
$target_path = $target_path .$new_name .'.'.$extensiontype; 

if(move_uploaded_file($_FILES['image_file']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['image_file']['name']). 
        " has been uploaded <br />";
} else{
    echo "There was an error uploading the file, please try again! <br />";

}

$product_img = $new_name.'.'.$extensiontype;

//ADD TO DATABASE
    $wpdb->query("INSERT INTO wp_rec_amazon_product (product_title, product_url,    product_img, product_btn_text) VALUES ('$product_title', '$product_url','$product_img','$product_btn_text')");
echo "You have successfully added "  .$product_title.   " to your products list";

} else { ?>

 <form action="<?PHP $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<table border="0" bordercolor="none" width="50%" cellpadding="0" cellspacing="0">
    <tr>
        <td>Product Title:</td>
        <td><input type="text" name="title" value="product title" /></td>
    </tr>
    <tr>
        <td>Product Url</td>
        <td><input type="text" name="url" value="product url" /></td>
    </tr>
    <tr>
        <td>Button text</td>
        <td><input type="text" name="btn_text" value="Get your copy" /></td>
    </tr>

</table>
    <input type="file" name="image_file" />



    <input type="submit" value="Submit" />
</form>

 <?PHP }?>

信息被添加到数据库中,只是图像上传似乎不起作用.

有人知道吗?谢谢大家.

php – WordPress tinyMCE自定义插件

php – WordPress tinyMCE自定义插件

我刚刚进入wordpress的插件开发.现在我有一个函数,我作为过滤器传递给’tiny_mce_before_init’,使用特定的变量来更改按钮,添加自定义样式和其他类似的东西.

我正在构建一个选项页面,我想控制传递给tinyMCE函数的变量,这样用户就可以选择要显示的按钮以及向编辑器添加自定义样式表.

在这一点上,我编辑微小的mce的功能很棒!选项页面还保存数据,复选框和我需要的其他所有内容.

我唯一的问题是我不了解如何将存储在“options.PHP”中的变量传递给当前的tinyMCE函数.这是我的functions.PHP文件中的当前函数:

function my_format_TinyMCE( $in ) {
    //styles for the editor to provide better visual representation.
    $in['content_css'] = get_template_directory_uri() . "/build/styles/tiny-mce-editor.css";
    $in['block_formats'] = "Paragraph=p; heading 1=h1; heading 2=h2";
    $in['toolbar1'] = 'formatselect,bold,italic,underline,superscript,bullist,numlist,alignleft,aligncenter,alignright,link,unlink,spellchecker';
    $in['toolbar2'] = '';
    $in['toolbar3'] = '';
    $in['toolbar4'] = '';
    return $in;
}
add_filter( 'tiny_mce_before_init','my_format_TinyMCE' );

我不想通过添加我的选项页面的所有代码来收集帖子,但是我可能需要一些关于如何处理传递变量作为$in []的值的方向.如前所述,变量将在选项页面中创建并保存,更新微小的mce函数.

我已经研究了很多,我找不到任何关于此的直接信息 – 像往常一样,我不是在寻找某人来做我的代码,但也许是为了让我朝着正确的方向前进.

谢谢!

编辑新代码

add_action('admin_menu','my_cool_plugin_create_menu');

function my_cool_plugin_create_menu() {
    add_menu_page('My Cool Plugin Settings','Cool Settings','administrator',__FILE__,'my_cool_plugin_settings_page',plugins_url('/images/icon.png',__FILE__) );
    add_action( 'admin_init','register_my_cool_plugin_settings' );
}

function register_my_cool_plugin_settings() {
    //register our settings
    register_setting( 'my-cool-plugin-settings-group','new_option_name' );
}

function my_cool_plugin_settings_page() {
    ?>
    <div>
        <h2>Your Plugin Name</h2>
        <form method="post" action="options.PHP">
            <?PHP settings_fields( 'my-cool-plugin-settings-group' ); ?>
            <?PHP do_settings_sections( 'my-cool-plugin-settings-group' ); ?>
            <table>
                <tr valign="top">
                    <th scope="row">New Option Name</th>
                    <td><input type="text" name="new_option_name" value="<?PHP echo esc_attr( get_option('new_option_name') ); ?>" /></td>
                </tr>

            <?PHP submit_button(); ?>
        </form>
    </div>
<?PHP }

function my_format_TinyMCE( $in ) {

    $toolbar = get_option('new_option_name');

    //styles for the editor to provide better visual representation.
    $in['content_css'] = get_template_directory_uri() . "/build/styles/tiny-mce-editor.css";
    $in['block_formats'] = "Paragraph=p; heading 1=h1; heading 2=h2";
    $in['toolbar1'] = $toolbar;
    $in['toolbar2'] = '';
    $in['toolbar3'] = '';
    $in['toolbar4'] = '';
    return $in;
}
    add_filter( 'tiny_mce_before_init','my_format_TinyMCE' );
?>

我仍然无法访问存储的变量并在函数中使用它们.有任何想法吗?

解决方法

在选项页面上,您可以使用 update_option保存选项.然后,在my_format_TinyMCE函数中,您可以使用 get_option访问它们.

php – WordPress自定义小部件记住多个选择选项

php – WordPress自定义小部件记住多个选择选项

我正在为我们的网站编写一个自定义小部件来显示一些选定的帖子.在管理部分,我有一个多选框,让管理员按名称选择多个帖子.这工作正常,但是当我选择几个不同的帖子并保存时,没有任何东西被保存.

任何人都可以对此有所了解吗?

这是我的代码……

<?PHP
/* 
Plugin Name: Hot Topics
Plugin URI: http://www.weddingideasmag.com
Description: Use this widget to choose an array of posts snippets to show
Version: 1.0)
Author: James Payne
Author URI: http://www.bluntcreative.co.uk
License: GPL2
*/


class Hottopics extends WP_Widget {

// constructor
function Hottopics() {
    $widget_ops = array( 'name' => 'Hot Topics','classname' => 'widget-hot-topics', 'description' => __( "Use this widget to choose an array of posts snippets to show in the sidebar." ) );
    $this->WP_Widget( 'hottopics', __('Hot Topics'), $widget_ops);
}

// widget form creation
function form($instance) {  
    // Check values
    if( $instance) {
        $select = esc_attr($instance['select']); // Added 
    } else {
         $select ='';
    }
    ?>

    <select multiple="multiple" name="<?PHP echo $this->get_field_name('select'); ?>[]" id="<?PHP echo $this->get_field_id('select'); ?>"size="15"https://www.jb51.cc/tag/ott/" target="_blank">ottom:15px;">
        <?PHP
        $args = array( 'offset'=> 1, 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => 200, 'post_status' => 'publish' );

        // The Query
        query_posts( $args );

        // The Loop
        while ( have_posts() ) : the_post();

        $title = get_the_title();
        ?>
            <option value="<?PHP echo get_the_ID();?>"<?PHP $select == $title ? ' selected="selected"' : '';?>https://www.jb51.cc/tag/ott/" target="_blank">ottom:3px;">
                <?PHP echo $title;?>
            </option>
            <?PHP
        endwhile;

        // Reset Query
        wp_reset_query();
        ?>
    </select>

    <?PHP
}

// update widget
function update($new_instance, $old_instance) {
      $instance = $old_instance;
      // Fields
      $instance['select'] = strip_tags($new_instance['select']);
     return $instance;
}

// widget display
function widget($args, $instance) {
    /* ... */
    echo 'tetst';
}
}

// register widget
add_action('widgets_init', create_function('', 'return register_widget("Hottopics");'));

?>

解决方法:

更新窗口小部件时,strip_tags正在销毁所选帖子的数组. esc_sql完成这项工作.另外,don’t use query_posts.最后,存储帖子标题并不理想,因为它可能会改变,ID是永久性的.

一份工作样本:

# PHP 5.3+ anonymous function
add_action( 'widgets_init', function() {
    register_widget( 'Sample_Widget_SO_19246434' );
});

class Sample_Widget_SO_19246434 extends WP_Widget 
{
    function Sample_Widget_SO_19246434() 
    {
        $this->WP_Widget( 
            'hottopics', 
            __('Hot Topics'),
            array( 
                'name' => 'Hot Topics',
                'classname' => 'widget-hot-topics', 
                'description' => __( "Description" ) 
            )
        );
    }

    function form( $instance ) 
    {
        if( $instance ) 
            $select = $instance['select'];
        else
             $select ='';

        $get_posts = get_posts( array( 
            'offset'=> 1, 
            'orderby' => 'date', 
            'order' => 'DESC', 
            'posts_per_page' => 200, 
            'post_status' => 'publish' 
        ));
        if( $get_posts )
        {
            printf(
                '<select multiple="multiple" name="%s[]" id="%s"size="15">',
                $this->get_field_name('select'),
                $this->get_field_id('select')
            );
            foreach( $get_posts as $post )
            {
                printf(
                    '<option value="%s"%shttps://www.jb51.cc/tag/ott/" target="_blank">ottom:3px;">%s</option>',
                    $post->ID,
                    in_array( $post->ID, $select) ? 'selected="selected"' : '',
                    $post->post_title
                );
            }
            echo '</select>';
        }
        else
            echo 'No posts found :(';
    }

    function update( $new_instance, $old_instance ) 
    {
        $instance = $old_instance;
        $instance['select'] = esc_sql( $new_instance['select'] );
        return $instance;
    }

    function widget( $args, $instance ) 
    {
        echo 'Hello world';
    }
}

有关:
 •What’s the difference between esc_* functions?
 •How to sanitize user input?

php – wordpress自定义查询选择元值

php – wordpress自定义查询选择元值

SELECT b.post_title, a.post_id, COUNT( * ) as Total
FROM  wp_posts b INNER JOIN 
            wp_postMeta a ON a.post_id = b.ID
    WHERE a.Meta_value = 1
      AND a.Meta_key = 'type-select' 
      AND b.post_status = 'publish'
      and post_type = 'car-cc'
GROUP BY b.post_title, a.post_id

目前它选择帖子标题和帖子ID,但我还需要选择元值,其中元键=类型 – 问题是另一个元键已经在查询中进行了比较.

sql小提琴:http://sqlfiddle.com/#!2/109c2/1

解决方法:

干得好

SELECT b.post_title, a.post_id, COUNT( * ) AS Total,
(SELECT Meta_value FROM  `wp_postMeta` WHERE post_id= b.ID AND Meta_key='type-gen') AS 'new  Meta value'
FROM  wp_posts b INNER JOIN 
            wp_postMeta a ON a.post_id = b.ID
    WHERE a.Meta_value = 1
      AND a.Meta_key = 'type-select' 
      AND b.post_status = 'publish'
      AND post_type = 'car-cc'
GROUP BY b.post_title, a.post_id

Fiddle

php – 在我自己的自定义插件中添加wordpress admin中的分页

php – 在我自己的自定义插件中添加wordpress admin中的分页

我想在我的插件页面中显示分页,由我创建..我尝试了很多例子,但没有人工作..

如果有人能给出答案我会感激不尽的…

注意:我希望在后端(在管理员中)不在前端进行分页

解决方法:

简单步骤:

$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;

查找记录总数

$limit = 10; // number of rows in page
$offset = ( $pagenum - 1 ) * $limit;
$total = $wpdb->get_var( "SELECT COUNT(`id`) FROM {$wpdb->prefix}table_name" );
$num_of_pages = ceil( $total / $limit );

给予限制:

$entries = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}table_name LIMIT $offset, $limit" );

将此代码添加到您想要分页的位置:

$page_links = paginate_links( array(
    'base' => add_query_arg( 'pagenum', '%#%' ),
    'format' => '',
    'prev_text' => __( '&laquo;', 'text-domain' ),
    'next_text' => __( '&raquo;', 'text-domain' ),
    'total' => $num_of_pages,
    'current' => $pagenum
) );

if ( $page_links ) {
    echo '<div><div>' . $page_links . '</div></div>';
}

我们今天的关于PHP图像上传(WordPress自定义插件)php图片上传插件的分享已经告一段落,感谢您的关注,如果您想了解更多关于php – WordPress tinyMCE自定义插件、php – WordPress自定义小部件记住多个选择选项、php – wordpress自定义查询选择元值、php – 在我自己的自定义插件中添加wordpress admin中的分页的相关信息,请在本站查询。

本文标签: