5
내 WordPress 사이트에서 축소판으로 사용하기 위해 원격 서버에서 이미지를 복사하려고합니다. 이 이미지 중 일부는 복사 한 후에 손상됩니다. 무슨 뜻인지 보여줍니다 여기에 복사 후 이미지가 손상되었습니다.
$url = 'http://media.cultserv.ru/i/1000x1000/'.$event->subevents[0]->image;
$timeout_seconds = 100;
$temp_file = download_url($url, $timeout_seconds);
if(!is_wp_error($temp_file)) {
$file = array(
'name' => basename($url),
'type' => wp_check_filetype(basename($url), null),
'tmp_name' => $temp_file,
'error' => 0,
'size' => filesize($temp_file),
);
$overrides = array(
'test_form' => false,
'test_size' => true,
'test_upload' => true,
);
$results = wp_handle_sideload($file, $overrides);
if(empty($results['error'])) {
$filename = $results['file'];
$local_url = $results['url'];
$type = $results['type'];
$attachment = array(
'post_mime_type' => $results['type'],
'post_title' => preg_replace('/.[^.]+$/', '', basename($results['file'])),
'post_content' => '',
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_parent' => $pID,
);
$attachment_id = wp_insert_attachment($attachment, $filename);
if($attachment_id) {
set_post_thumbnail($pID, $attachment_id);
}
}
}
이 스크린 샷입니다 (왼쪽 - 원본 이미지를, 오른쪽 - 내 서버에 복사) : 여기
내 코드의
'$ attachData = wp_generate_attachment_metadata ($ attachment_id, $ 파일 이름)을 사용하십시오; wp_update_attachment_metadata ($ attach_id, $ attachData)''와; 'set_post_thumbnail'을 호출하고 결과 이미지가 개선되는지 확인하십시오. 스크립트의 어딘가에'require_once (ABSPATH. 'wp-admin/includes/image.php');가 있는지 확인하십시오. – fyrye
문제는 $ local_url에 저장된 URL로 액세스 할 수있는 이미지가 이미 손상되었음을 나타냅니다. 첨부 파일이 생성되기 전에입니다. –