Acaba aynı resmi tekrar tekrar yüklemeyi engelleyip herzaman daha önce yüklenmiş olan bir resmi nasıl kullanabilirim?
Kodlar:
if ($post_id = wp_insert_post($wpPost))
{
$filename = rand(0, 99999999).".jpg";
$resim="http://www.site.com/wp-content/uploads/2014/12/911x445.jpg";
$uploads = wp_upload_dir(current_time('mysql'));
$filename = wp_unique_filename( $uploads['path'], $filename );
$new_file = $uploads['path'] . "/$filename";
$file_data = vericek($resim);
file_put_contents($new_file, $file_data);
$stat = stat( dirname( $new_file ));
$perms = $stat['mode'] & 0000666;
@ chmod( $new_file, $perms );
$wp_filetype = wp_check_filetype( $filename, $mimes );
extract( $wp_filetype );
if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) ) {
echo "unfiltered_upload: logo hatası";}
$url = $uploads['url'] . "/$filename";
// Construct the attachment array
$attachment = array(
'post_mime_type' => $type,
'guid' => $url,
'post_parent' => null,
'post_title' => $filename,
'post_content' => '',
);
$thumb_id = wp_insert_attachment($attachment, $file, $post_id);
if ( !is_wp_error($thumb_id) ) {
require_once(ABSPATH . '/wp-admin/includes/image.php');
// Added fix by misthero as suggested
wp_update_attachment_metadata( $thumb_id, wp_generate_attachment_metadata( $thumb_id, $new_file ) );
update_attached_file( $thumb_id, $new_file );
}
wp_set_post_tags( $post_id, $etikett, false );
add_post_meta($post_id, '_thumbnail_id', $thumb_id);
add_post_meta($post_id, '_aioseop_keywords', $etiket);
add_post_meta($post_id, 'link', $md5);
echo 'Eklendi: ' . $baslik;
}