更改新目录wp_handle_upload

时间:2014-05-08 10:25:54

标签: php wordpress

我当前的路径是=

(localhost / wordpress / wp-content / uploads / 2014/05 / Koala81.jpg);

我设置此路径=

(localhost / wordpress / wp-content / plugins / xd / product_image / Koala81.jpg);

if(!function_exists(' wp_handle_upload'))require_once(ABSPATH。' wp-admin / includes / file.php');

$uploadedfile = $_FILES['file'];

$upload_overrides = array( 'test_form' => false );

$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );

$product_image = $movefile['url'];


     $data = array(
            'title'    => $_POST['title'],
            'description'    => $_POST['description'],
            'type'    => $_POST['type'],
            'vendor'  => $_POST['vendor'],
            'price'    => $_POST['price'],
            'comprice'  => $_POST['comprice'],
            'sku'     => $_POST['sku'],
            'barcode'  => $_POST['barcode'],
            'chargetaxes'  => $_POST['chargetaxes'],
            'shopadd'  => $_POST['shopadd'],
            'promulti'  => $_POST['promulti'],
            'product_status'  => $_POST['product_status'],
            'featured_image'  => $_POST['featured_image'],
            'file'  => $product_image,
            'tags'  => $_POST['tags'],
            'search'    => $_POST['search'],
            'meta'    => $_POST['meta'],
            'url'    => $_POST['url'],


        );


        $success=$wpdb->insert( $table, $data);

        $lastid = $wpdb->insert_id;

        if($success == 1 && $_POST['featured_image'] == 'Yes')
        {
            $featured_image_product = $wpdb->query("UPDATE $table SET featured_image = 'No' where id != '$lastid'");
        }

        if($success){
            echo "<h3 style='color:green;text-align:center;'>"."Products Added"."</h3>"; 
        } else {
            echo $wpdb->print_error();
        }
} 

1 个答案:

答案 0 :(得分:3)

文件上传路径不能是网址,因此你必须使用这样的路径&#34; wp-content / plugins / xd / product_image / Koala81.jpg&#34;