Mime_content_type error saat dihosting

Message : Uncaught Error: Call to undefined function mime_content_type() in /home/ucteq9wi/public_html/admin/app/modules/filepicker/filepicker.php:216 Stack trace: #0 /home/ucteq9wi/public_html/admin/index.php(172): include() #1 {main} thrown

Agan agan untuk masalah Diatas mime_content_type error saat dihosting sedangkan pas dilocal bisa. Itu permasalahanya dimana dan solusinya gimana gan?
avatar Maulidi118

@Maulidi118

4 Kontribusi 0 Poin


Jawaban

Pastikan versi php antara local dan hosting itu sama ya gan
avatar ahanafi

@ahanafi

760 Kontribusi 498 Poin

  • Terima kasih gan solusinya akan saya coba dulu - @Maulidi118


Masih belum bisa gan. Apakah ada eksistensi atau fungsi yang harus diaktifkan dalam cpanel hostingnya?
avatar Maulidi118

@Maulidi118

4 Kontribusi 0 Poin


coba dengan ini

function mime_content_type($filename) {
    $result = new finfo();

    if (is_resource($result) === true) {
        return $result->file($filename, FILEINFO_MIME_TYPE);
    }

    return false;
}

sumber : https://stackoverflow.com/questions/1263957/why-is-mime-content-type-deprecated-in-php
avatar mitsuky06

@mitsuky06

52 Kontribusi 17 Poin


untuk kodinganya seperti ini gan. kalau ada kesalahan atau penambahan kode. mohon koreksinya.
	case 'ajax-upload-file' :
	
		$path = $config['filepicker_upload_path'];

		if ( !empty($_FILES) ) {
						
			if ( file_exists($path) && is_dir($path) ) {
				
				if ( !is_writable($path) ) {
					$result = array (
						'status' => 'error',
						'message'   => 'Tidak dapat menulis file ke folder'
					);
					
				} else {

					$new_name = upload_file($path, $_FILES['file']);
					if ($new_name) {
						
						$meta_file = [];
						
						$mime_image = ['image/png', 'image/jpeg', 'image/bmp', 'image/gif'];
						$current_mime_type = mime_content_type($path . $new_name);
						
						if (in_array($current_mime_type, $mime_image)) 
						{
							$img_size = @getimagesize($path . $new_name);
						
							$meta_file['default'] = ['width' => $img_size[0]
														, 'height' => $img_size[1]
														, 'size' => $_FILES['file']['size']
													];

							foreach ($config['thumbnail'] as $size => $dim) 
							{
							
								if ($img_size[0] > $dim['w'] || $img_size[1] > $dim['h']) 
								{
									$img_dim = image_dimension($path. $new_name, $dim['w'], $dim['h']);
									$img_width = ceil($img_dim[0]);
									$img_height = ceil($img_dim[1]);
									
									$width = $height = null;
									if ($img_width >= $dim['w']) {
										
										$width = $dim['w'];
										
									} else if ($img_height >= $dim['h']) {
										
										$height = $dim['h'];
									}

									$layer = ImageWorkshop::initFromPath($path . $new_name);
									$layer->resizeInPixel($width, $height, true);
									$name_path = pathinfo($new_name);
									$thumb_name = $name_path['filename'] . '_' . $size . '.' . $name_path['extension'];
									$layer->save($path, $thumb_name, false, false, 97);
									
									$thumb_dim =  @getimagesize($path . $thumb_name);
									$meta_file['thumbnail'][$size] = [
															'filename' => $thumb_name
															, 'width' => $thumb_dim[0]
															, 'height' => $thumb_dim[1]
															, 'size' => @filesize($path . $thumb_name)
														];
								}
							}
						}
						
						$data_db['nama_file'] = $new_name;
						$data_db['mime_type'] = $current_mime_type;
						$data_db['size'] = $_FILES['file']['size'];
						$data_db['tgl_upload'] = date('Y-m-d H:i:s');
						$data_db['id_user_upload'] = $_SESSION['user']['id_user'];
						$data_db['meta_file'] = json_encode($meta_file);
						
						$sql = $db->insert('file_picker', $data_db);
						
						$file_info = $data_db;
						$file_info['bulan_upload'][date('Y-m')] = $nama_bulan[date('n')] . ' ' . date('Y');
						$file_info['id_file_picker'] = $db->lastInsertId();
						$result = get_file_properties($current_mime_type, $new_name, $meta_file);
						$file_info = array_merge($file_info, $result);
						
						$result = [
								'status'    => 'success',
								'message'      => 'File berhasil diupload.',
								'file_info' => $file_info
						];
					} else {
						$result = [
							'status' => 'error',
							'message'   => 'System error'
						];
					}
				}

			} else {
				$result = [
					'status' => 'error',
					'message'   => 'Folder ' . $path . ' tidak ditemukan'
				];
			}
			
			

			// Return the response
			echo json_encode($result);
			exit;
		}
avatar Maulidi118

@Maulidi118

4 Kontribusi 0 Poin

  • coba script jawabanku di taruh di atas if ( !empty($_FILES) ) { ,,, kalo masi error,, errornya berubah atau tidak,,, - @mitsuky06
  • Masih error gan - @Maulidi118
  • iyaa,,, errornya masi sama atau berubah ? - @mitsuky06

Tampikan semua |


Login untuk gabung berdiskusi