• Resolved Slavianqwerty

    (@slavianqwerty)


    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://www.ads-software.com/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

    (@stianlik)

    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.

    You may also get some useful information from the thread Regenerate Thumbnails.

    • This reply was modified 7 years, 8 months ago by stianlik.
Viewing 1 replies (of 1 total)
  • The topic ‘Program to create thumbnail’ is closed to new replies.