Title: Program to create thumbnail
Last modified: September 29, 2016

---

# Program to create thumbnail

 *  Resolved [Slavianqwerty](https://wordpress.org/support/users/slavianqwerty/)
 * (@slavianqwerty)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/program-to-create-thumbnail/)
 * Hello. Prompt how to create a preview of the PDF file is downloaded to their 
   handler.
    sample code
 *     ```
       <form method="post" action="<?php bloginfo('template_url'); ?>/handler.php" enctype="multipart/form-data" class="form-horizontal">
        	<?php wp_nonce_field( 'pdf_files', 'fileup_nonce' ); ?>
   
   
       	<input name="pdf_files" id="uploades" required type="file" class="custom_media_url"/>
       	<input name="xsq" class="get-val" value=""/>
        <button id="send" name="send" class="btn btn-primary">Отправить</button>
       </form>
       ```
   
 * and handler.php
 *     ```
       if(isset($_POST['send']) == '1') {
        $new_post = array(
        'ID' => '',
        'post_author' => $user->ID,
        'post_category' => 'portfolio-party',
        'post_title' => $post_title,
        'post_status' => 'publish'
        );
       $post_id = wp_insert_post($new_post);
       if ( ! function_exists( 'wp_handle_upload' ) ) {
       	require_once( ABSPATH . 'wp-admin/includes/file.php' );
       }
   
       $uploadedfile = $_FILES['pdf_files'];
       $upload_overrides = array( 'test_form' => false );
       $movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
       if ( $movefile && !isset( $movefile['error'] ) ) {
       	$filename = $movefile['file'];
       	$parent_post_id = $applicant_id;
       	$wp_upload_dir = wp_upload_dir();
       	$attachment = array(
       		'guid'           => $wp_upload_dir['url'] . '/' . basename( $filename ), 
       		'post_mime_type' => $filetype['type'],
       		'post_title'     => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
       		'post_status'    => 'inherit'
       	);
   
       	// Insert the attachment.
       	$attach_id = wp_insert_attachment( $attachment, $filename, $parent_post_id );
       	//$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
       	wp_update_attachment_metadata( $attach_id, $attach_data );
   
       	// Update File Field
       	update_field('pdf_files', $attach_id, $post_id);
       } else {
   
       }
       ```
   
 * I tried to add the code in this topic, but not work.
    [https://wordpress.org/support/topic/acf-front-end-editor/](https://wordpress.org/support/topic/acf-front-end-editor/)
 * I suspect that your plug-in only if the file is saved in admin’s part.
 * If anything, I’m sorry for my english.

Viewing 1 replies (of 1 total)

 *  Plugin Author [stianlik](https://wordpress.org/support/users/stianlik/)
 * (@stianlik)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/program-to-create-thumbnail/#post-8968318)
 * Sorry for the late response, I thought I had answered this one already.
 * You are correct, the plugin attaches to the `wp_generate_attachment_metadata`
   event, which is triggered on file uploads. Using a third-party plugin like ACF,
   may require some custom code to trigger the generator.
 * I have not implemented a public API for this, but it is possible to trigger the
   process manually by calling `pdf_thumbnails_generate_attachment_metadata(null,
   $attach_id)`, [see source code](https://plugins.trac.wordpress.org/browser/pdf-thumbnails/tags/2.2.0/pdf-thumbnails.php#L31).
 * You may also get some useful information from the thread [Regenerate Thumbnails](https://wordpress.org/support/topic/regenerate-thumbnails-3/).
    -  This reply was modified 9 years, 2 months ago by [stianlik](https://wordpress.org/support/users/stianlik/).

Viewing 1 replies (of 1 total)

The topic ‘Program to create thumbnail’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/pdf-thumbnails.svg)
 * [PDF Thumbnails](https://wordpress.org/plugins/pdf-thumbnails/)
 * [Support Threads](https://wordpress.org/support/plugin/pdf-thumbnails/)
 * [Active Topics](https://wordpress.org/support/plugin/pdf-thumbnails/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/pdf-thumbnails/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/pdf-thumbnails/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [stianlik](https://wordpress.org/support/users/stianlik/)
 * Last activity: [9 years, 2 months ago](https://wordpress.org/support/topic/program-to-create-thumbnail/#post-8968318)
 * Status: resolved