Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

nexxoz on "[HELP] Upload to MEDIA library"

$
0
0

Im currently working on a plugin to my project and i want users to be able to upload images to the media library the problem is that the code dosen't make a thumbnail image or add watermark by the Easy watermark plugin, help plz

if ( ! function_exists( 'wp_handle_upload' ) ) require_once( ABSPATH . 'wp-admin/includes/file.php' );
	$uploadedfile = $_FILES['myfile'];
	$upload_overrides = array( 'test_form' => false );
	$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );

		if ( $movefile ) {
		    $wp_filetype = $movefile['type'];
		    $filename = $movefile['file'];
		    $wp_upload_dir = wp_upload_dir();
		    $attachment = array(
		        'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ),
		        'post_mime_type' => $wp_filetype,
		        'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
		        'post_content' => '',
		        'post_status' => 'inherit'
		    );
		    $attach_id = wp_insert_attachment( $attachment, $filename);
		    $text = 'Image uploaded! Waiting to be accepted by admins';
		}

	}

	if(empty($text)){

	echo '<form role="form" method="post" enctype="multipart/form-data">';
	echo '  <div class="form-group">';
	echo '    <label for="exampleInputFile">Välj fil</label>';
	echo '    <input type="file" name="myfile">';
	echo '   <p class="help-block">Minst 250x250px</p>';
	echo '  </div>';
	echo ' <button type="submit" name="ch-upload" class="btn btn-default">Ladda upp</button>';
	echo '</form>';

	}else{
		echo $text;
	}

Viewing all articles
Browse latest Browse all 8245

Trending Articles