Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: mime type error

  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts

    mime type error

    Can anyone help me here, i'm getting:
    Code:
    Warning: image_type_to_mime_type() expects parameter 1 to be long
    here's the line:

    PHP Code:
    $aAllowedMimes array_map('image_type_to_mime_type'$allowed); 
    here's $allowed:

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

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    738
    Thanks
    20
    Thanked 85 Times in 85 Posts
    PHP Code:
    if ( !function_exists('image_type_to_mime_type') ) {

        function 
    image_type_to_mime_type ($type)
        {
            
    $m = array ( => '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];
        }



  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    PHP Code:
    $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.im...-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?
    Last edited by Keleth; 07-23-2012 at 07:10 PM.

  • Users who have thanked Keleth for this post:

    Arcticwarrio (07-24-2012)

  • #4
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    ahaa! So it should be
    PHP Code:
    $allowed[] = image/XXX
    ???????

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Case matters for constants. Read the documentation I linked.

  • #6
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    done it,
    PHP Code:
    $allowed[] =         IMAGETYPE_JPEG
    $allowed[] =         IMAGETYPE_GIF
    $allowed[] =         IMAGETYPE_PNG
    $allowed[] =         IMAGETYPE_BMP 

  • #7
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    can any one tell me how to get the mime quick, so i can pass it to create_thumb(), here's my upload func:
    PHP Code:
        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'] .'/');
                    }
                }
                
            }
        } 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •