• 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 HR, 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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Where are the images uploaded from? It cannot be your local computer, it must be on a server somewhere.

    If the image is available online when the CRON runs, there could be a permissions issue. WordPress typically runs as www-data user. If the CRON script is run as a different user, that user would need write permission to the tmp folder as well as uploads.

    One way to check if it’s a permission issue is to temporarily change the permissions so all users can write. Just don’t leave it that way, it’s a huge security hole!

    Thread Starter marcin1990

    (@marcin1990)

    Thanks,i forget about:

    require_once(ABSPATH . "wp-admin" . '/includes/image.php');
    require_once(ABSPATH . "wp-admin" . '/includes/file.php');
    require_once(ABSPATH . "wp-admin" . '/includes/media.php');

    It’s working

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘cron do not upload images’ is closed to new replies.