Postingan lainnya
Buku Ini Koding!
Baru!
Buku ini akan jadi teman perjalanan kamu belajar sampai dapat kerjaan di dunia programming!
Kelas Premium!
Belajar Javascript untuk website
Gunakan kupon "mulaijs" untuk diskon 75 ribu!
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?
4 Jawaban:
<div>Pastikan versi php antara local dan hosting itu sama ya gan</div>
Tanggapan
Terima kasih gan solusinya akan saya coba dulu
<div>Masih belum bisa gan. Apakah ada eksistensi atau fungsi yang harus diaktifkan dalam cpanel hostingnya?</div>
<div>coba dengan ini<br><br></div><pre>function mime_content_type($filename) { $result = new finfo();
if (is_resource($result) === true) {
return $result-&gt;file($filename, FILEINFO_MIME_TYPE);
}
return false;
}</pre><div><br>sumber : https://stackoverflow.com/questions/1263957/why-is-mime-content-type-deprecated-in-php</div>
<div>untuk kodinganya seperti ini gan. kalau ada kesalahan atau penambahan kode. mohon koreksinya.</div><div><br></div><pre> case 'ajax-upload-file' :
$path = $config['filepicker_upload_path'];
if ( !empty($_FILES) ) {
if ( file_exists($path) &amp;&amp; is_dir($path) ) {
if ( !is_writable($path) ) {
$result = array (
'status' =&gt; 'error',
'message' =&gt; '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' =&gt; $img_size[0]
, 'height' =&gt; $img_size[1]
, 'size' =&gt; $_FILES['file']['size']
];
foreach ($config['thumbnail'] as $size =&gt; $dim)
{
if ($img_size[0] &gt; $dim['w'] || $img_size[1] &gt; $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 &gt;= $dim['w']) {
$width = $dim['w'];
} else if ($img_height &gt;= $dim['h']) {
$height = $dim['h'];
}
$layer = ImageWorkshop::initFromPath($path . $new_name);
$layer-&gt;resizeInPixel($width, $height, true);
$name_path = pathinfo($new_name);
$thumb_name = $name_path['filename'] . '_' . $size . '.' . $name_path['extension'];
$layer-&gt;save($path, $thumb_name, false, false, 97);
$thumb_dim = @getimagesize($path . $thumb_name);
$meta_file['thumbnail'][$size] = [
'filename' =&gt; $thumb_name
, 'width' =&gt; $thumb_dim[0]
, 'height' =&gt; $thumb_dim[1]
, 'size' =&gt; @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-&gt;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-&gt;lastInsertId();
$result = get_file_properties($current_mime_type, $new_name, $meta_file);
$file_info = array_merge($file_info, $result);
$result = [
'status' =&gt; 'success',
'message' =&gt; 'File berhasil diupload.',
'file_info' =&gt; $file_info
];
} else {
$result = [
'status' =&gt; 'error',
'message' =&gt; 'System error'
];
}
}
} else {
$result = [
'status' =&gt; 'error',
'message' =&gt; 'Folder ' . $path . ' tidak ditemukan'
];
}
// Return the response
echo json_encode($result);
exit;
}</pre>
Tanggapan
coba script jawabanku di taruh di atas if ( !empty($_FILES) ) { ,,, kalo masi error,, errornya berubah atau tidak,,,
Masih error gan
iyaa,,, errornya masi sama atau berubah ?
Errornya mlaha di koding fungsi tersebut gan