我可以使用命令
将本地文件上传到远程服务器 public function ajax_search_products() {
global $woocommerce;
$search_keyword = $_REQUEST['query'];
$ordering_args = $woocommerce->query->get_catalog_ordering_args( 'title', 'asc' );
$suggestions = array();
$args = array(
's' => apply_filters( 'yith_wcas_ajax_search_products_search_query', $search_keyword ),
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'orderby' => $ordering_args['orderby'],
'order' => $ordering_args['order'],
'posts_per_page' => apply_filters( 'yith_wcas_ajax_search_products_posts_per_page', get_option( 'yith_wcas_posts_per_page' ) ),
'suppress_filters' => false,
'meta_query' => array(
array(
'key' => '_visibility',
'value' => array( 'search', 'visible' ),
'compare' => 'LIKE'
)
)
);
if ( isset( $_REQUEST['product_cat'] ) ) {
$args['tax_query'] = array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $_REQUEST['product_cat']
) );
}
$products = get_posts( $args );
if ( !empty( $products ) ) {
foreach ( $products as $post ) {
$product = wc_get_product( $post );
$suggestions[] = apply_filters( 'yith_wcas_suggestion', array(
'id' => $product->id,
'value' => strip_tags($product->get_title()),
'url' => $product->get_permalink()
), $product );
}
}
else {
$suggestions[] = array(
'id' => - 1,
'value' => __( 'No results', 'yith-woocommerce-ajax-search' ),
'url' => '',
);
}
wp_reset_postdata();
$suggestions = array(
'suggestions' => $suggestions
);
但我无法将远程文件上传到该网址。我正在使用的命令就是这个
curl -T abc.pom -uusername:password URL
不可能这样做吗?是下载它然后再次上传它是唯一的选择吗?
答案 0 :(得分:4)
我的方法:
TF=/tmp/temp && curl <REMOTE_FILE_URL> -o $TF && curl -T $TF <UPLOAD_URL> && rm -f $TF
有可能将文件内容从第1个cURL传递到第2个cURL,但第二个必须自己准备HTML表单编码的主体。 -T是这方面的简写 - 它创建表单并直接填充它:
curl <REMOTE_FILE_URL> | curl -i -X POST -H "Content-Type: multipart/form-data" -d @- <UPLOAD_URL>
答案 1 :(得分:-1)
您可以通过ssh
向目标主机发送命令直接从远程主机卷曲:
ssh user@destination_host 'curl -o destination_file_path remote_file_url'