...

View Full Version : mime type error



Chris-2k
07-23-2012, 05:12 PM
Can anyone help me here, i'm getting:


Warning: image_type_to_mime_type() expects parameter 1 to be long


here's the line:


$aAllowedMimes = array_map('image_type_to_mime_type', $allowed);

here's $allowed:


$allowed[] = 'IMAGE_GIF';
$allowed[] = 'IMAGE_JPEG';
$allowed[] = 'IMAGE_PNG';
$allowed[] = 'IMAGE_BMP'; // allowed image types, to add more use: 'image{type}',

Arcticwarrio
07-23-2012, 06:43 PM
if ( !function_exists('image_type_to_mime_type') ) {

function image_type_to_mime_type ($type)
{
$m = array ( 1 => 'image/gif', 'image/jpeg', 'image/png',
'application/x-shockwave-flash', 'image/psd', 'image/bmp',
'image/tiff', 'image/tiff', 'application/octet-stream',
'image/jp2', 'application/octet-stream', 'application/octet-stream',
'application/x-shockwave-flash', 'image/iff', 'image/vnd.wap.wbmp', 'image/xbm');

// We are expecting an integer.
$type = (int)$type;
if (!$type) {
trigger_error( '...come up with an error here...', E_USER_NOTICE );
return null;
}

if ( !isset($m[$type]) ) {
trigger_error( '...come up with an error here...' E_USER_NOTICE );
return null;
}

return $m[$type];
}

}

Keleth
07-23-2012, 07:05 PM
$allowed[] = 'IMAGE_GIF';

Adds a string to $allowed. image_type_to_mime_type expects a constant. Drop the quotes. You're also not using the right 'constants', see http://php.net/manual/en/function.image-type-to-mime-type.php

Also Arcticwarrio, why add a whole function where you have to feed/memorize int values or make use of the same constants the standard image_type_to_mime_type uses, when the original function exists?

Chris-2k
07-23-2012, 10:58 PM
ahaa! So it should be
$allowed[] = image/XXX;

???????

Keleth
07-23-2012, 11:14 PM
Case matters for constants. Read the documentation I linked.

Chris-2k
07-23-2012, 11:33 PM
done it,
$allowed[] = IMAGETYPE_JPEG;
$allowed[] = IMAGETYPE_GIF;
$allowed[] = IMAGETYPE_PNG;
$allowed[] = IMAGETYPE_BMP

Chris-2k
07-26-2012, 07:06 PM
can any one tell me how to get the mime quick, so i can pass it to create_thumb(), here's my upload func:
function performUploadandCreateThumb($files, array $aConfig) {
if($ext = checkitsaValidImage($files))
{
$new_name = gen_uniqueFilename() . $ext; // we will give an unique name.

if(loggedin) {
$album_id = $_POST['album_id'];
$filePath = $aConfig['site_address'] .'/'. $aConfig['upload_destination'] .'/'. $album_id .'/'. $new_name;
// Upload image
move_uploaded_file($files, $aConfig['upload_destination'] .'/'. $album_id .'/'. $new_name);
// Create the thumbnail
if(isset($aConfig['custom_pixels']) && !empty($aConfig['custom_pixels']) && is_numeric($aConfig['custom_pixels'])) {
create_thumb($aConfig['custom_pixels'], $filePath, $ext, $aConfig['thumb_destination'] .'/'. $album_id .'/');
}
// Insert to DB
insertDBinfo($files, $aConfig, $new_name);
} else {
$filePath = $aConfig['site_address'] .'/'. $aConfig['upload_destination'] .'/'. $new_name;
// Upload image
move_uploaded_file($files, $aConfig['upload_destination'] .'/'. $new_name);
// Create the thumbnail
if(isset($aConfig['custom_pixels']) && !empty($aConfig['custom_pixels']) && is_numeric($aConfig['custom_pixels'])) {
create_thumb($aConfig['custom_pixels'], $filePath, $ext, $aConfig['thumb_destination'] .'/');
}
}

}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum