dsxz84851 2016-02-17 12:39 采纳率: 100%
浏览 32

Wordpress cron不上传图片

I let the task CRON product imports. The data are retrieved from the database in a loop. Each item has its own image, and in the database is only information which the link is located. I have this code. When you release the script manually add products properly. While connecting to the cron script is added to the product description and the script stops running. Folder uploads in WP, there is nothing thrown (in the case of manual firing script to a folder are uploaded image from the link).

My code to upload and load pictures. (When I delete this part of the code cron works and products are imported correctly)

$thumb_url = $foto1;
$tmp = download_url( $thumb_url );

preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $thumb_url, $matches);
$file_array['name'] = basename($matches[0]);
$file_array['tmp_name'] = $tmp;

$thumbid = media_handle_sideload( $file_array, $new_post_id, 'gallery desc' );

set_post_thumbnail($new_post_id, $thumbid);

$thumb_url2 = $foto2;

$tmp2 = download_url( $thumb_url2 );

preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $thumb_url2, $matches);

$file_array2['name'] = basename($matches[0]);
$file_array2['tmp_name'] = $tmp2;
$imgID = media_handle_sideload( $file_array2, $new_post_id, 'desc' );

update_post_meta( $new_post_id, '_product_image_gallery', $imgID);

I spent two days. The problem with access rights to the record? Wrong code? What could be causing this?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP