Reading Text File Contents Into Custom Field After Adding Attachment
-
This is failing on trying to read the text file contents into a custom field after adding an attachment and I for the life of me can’t figure out why:
function my_add_attachment_pdftext( $attachment_id ) {
$attachedfile = basename(get_attached_file($attachment_id));
$filetype = wp_check_filetype($attachedfile);if ($filetype[‘type’] == ‘application/pdf’){
$fileparts = explode(‘.’, $attachedfile);
$url = ‘https://www.mydomain.com/’ . $fileparts[0] . ‘.txt’;$file = fopen($url, ‘r’);
$text_data = fread($file, filesize($url));
fclose($file);update_post_meta( $attachment_id, ‘pdftext’, $text_data);
}
}
add_action( ‘add_attachment’, ‘my_add_attachment_pdftext’ );
- The topic ‘Reading Text File Contents Into Custom Field After Adding Attachment’ is closed to new replies.