HEX
Server: Apache/2
System: Linux ns65.hostinglotus.net 4.18.0-553.16.1.el8_10.x86_64 #1 SMP Thu Aug 8 07:11:46 EDT 2024 x86_64
User: newsnnno (1225)
PHP: 8.2.20
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/newsnnno/public_html/wp-content/plugins/file-manager/inc/class.media-sync.php
<?php 
/**
 * 
 * Synchronizing media file when a media file is uploaded. Media Files: Image, Audio, Video, Archive
 * @since 5.1
 * @package FileManager
 * 
 * */
// Security check
defined('ABSPATH') || die();

if( !class_exists('FMMediaSync') ):

// Sync current media library uploads to media library.
class FMMediaSync {

	public $wp_upload_directory;

	function __construct(){

		require_once( ABSPATH . 'wp-admin/includes/image.php' );

		$this->wp_upload_directory = wp_upload_dir();
		$this->wp_upload_directory = $this->wp_upload_directory['path'];

	}

	// Triggers when a file is uploaded and initiates the uploading process for single or batch files.
	public function onFileUpload($cmd, &$result, $args, $elfinder, $volume){
		$images = array();
		$I = 0;

		$upload_target_path = $volume->getPath($args['target']);

		if( strpos( $upload_target_path, $this->wp_upload_directory ) !== false ){
			
			$images = array();
            error_log(print_r($args, true));
            error_log(print_r($args['FILES'], true));
			for($I = 0; $I < count($args['FILES']['upload']['name']); $I++){
				
				$images[] = array(
					'name' => $args['FILES']['upload']['name'][$I],
					'type' => wp_check_filetype( $args['FILES']['upload']['name'][$I], null ),
					'path' => trailingslashit($upload_target_path) . $args['FILES']['upload']['name'][$I],
					'url' => $this->abs_path_to_url( trailingslashit($upload_target_path) . $args['FILES']['upload']['name'][$I] ),
				);

			}

			$this->add_media($images);

		}
		
	}
	
	private function add_media($images){
		foreach ($images as $image){
			$attachment = array(
				'post_mime_type' => $image['type']['type'],
				'post_title' => sanitize_file_name( $image['name'] ),
			);
			$attachment_id = wp_insert_attachment( $attachment, $image['path'] );
			$attach_data = wp_generate_attachment_metadata( $attachment_id, $image['path'] );
			wp_update_attachment_metadata( $attachment_id, $attach_data );
		}
	}

	private function abs_path_to_url( $path = '' ) {
	    $url = str_replace(
	        wp_normalize_path( untrailingslashit( ABSPATH ) ),
	        site_url(),
	        wp_normalize_path( $path )
	    );
	    return esc_url_raw( $url );
	}

}
endif;