• naviialto

    (@naviialto)


    if ( $img ) {
    				fwrite( $f, $img );
    				fclose( $f );
    				$local = $httppath . '/' . $domain . dirname ( $b['path'] ) . "/$filename";
    				$wpdb->query("UPDATE $wpdb->posts SET post_content = REPLACE(post_content, '$dummy5', '$local');");
    /////////////////////////////////////////////////////////////////////////////////////////////
    // http://wordpress.org/support/topic/180194
    $fullpath = $dir . '/' . $filename;
    if(file_exists($fullpath)) {
      $file = wp_load_image($fullpath);
      if (!is_resource($file)) {
        echo "Noway, this files doens't exists";
        die();
      }
    
      $attachment = array(
        'post_title' => $filename,
        'post_content' => '',
        'post_type' => 'attachment',
    	'guid' => $local,
        'post_parent' => $postidnum,
        'post_mime_type' => 'image/jpeg'
      );
    
      // Save the data
      $id = wp_insert_attachment($attachment, $fullpath, $postid );
    echo "id : ". $id . "<br />";
    echo "file : " . $fullpath . "<br />";
      wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $fullpath ) );
    }
    /////////////////////////////////////////////////////////////////////////////////////////////
    				echo "<li>Cached $url</li>";
    				flush();
    			}
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Hot Linked Image Cacher] push attachment code’ is closed to new replies.