So I have my image upload script and it seems to be working just fine except for when I try to upload a .bmp file then it get that the file is not an image.

<?php
public function addimage()
	{
	$this->data['title'] = $this->config->item('title')." - Process Add Image";
	$this->data['errors'] = array();

if( $this->session->userdata('user') )
	{		
	// Process image and add to database.
	$type = $_POST['gallery'];
	if( !$_FILES['image']['size'] > 1 ) $this->data['errors'][] = "Filesize error. Error Code #7101";

	// Set dir & thumb dir, create if not there
	$dir = $this->config->item('upload_path')."". date("mY",time());
	if( !is_dir($dir) ) mkdir($dir);

	$tndir = $dir ."\\thumbs";
	if( !is_dir($tndir) ) mkdir($tndir);

	$ext = pathinfo($_FILES["image"]['name']);
	$ext = $ext['extension'];
	$filename = microtime(TRUE);

	$temp = $dir ."\\{$filename}temp.{$ext}";
	$pic = $dir ."\\{$filename}.{$ext}";
	$tn = $tndir ."\\{$filename}.{$ext}";

	if( !@getimagesize($_FILES["image"]['tmp_name']) ) $this->data['errors'][] = "File is not an image. Error Code #7102";
	if( !move_uploaded_file($_FILES["image"]['tmp_name'],$temp) ) $this->data['errors'][] = "File unabled to be moved. Error Code #7104";

	if( sizeof($this->data['errors']) > 0 )
		{
		$this->load->view('global/errors',$this->data);
		return;
	}

	if( !$this->_imageResize($temp,$tn,"45","60",TRUE) ) $this->data['errors'][] = "Thumbnail resize failed. Error Code #7111";
	if( !$this->_imageResize($temp,$pic,"500","700") ) $this->data['errors'][] = "View resize failed. Error Code #7112";
	if( !unlink($temp) ) $this->data['errors'][] = "Temporary file deletion failed. Code #7113";

	if( sizeof($this->data['errors']) > 0 )
		{
		$this->load->view('global/errors',$this->data);
		return;
	}

	if( !$this->gallery->insertImage($type,$filename,$ext) )
		{
		$this->data['errors'][] = "Error inserting into database. Error Code #7121";
		$this->load->view('global/errors',$this->data);
		return;
	} else
		{				
		$this->data['message'] = "Image Successfully Uploaded";
	}

	$this->data['galleries'] = array();
	$result = $this->gallery->getGalleries();
	foreach($result->result() as $row)
		{
		$this->data['galleries'][$row->id] = $row->name;
	}

	$this->load->view("gallery/image_form",$this->data);
} else
	{
	$this->data['errors'][] = "You must be logged in to view this page. Error code #5000";
	header("Refresh: 5;url: ". $_SERVER['HTTP_HOST'] ."/");
	$this->load->view('global/errors',$this->data);
}
}

It works perfectly for jpg, gif and png files however it does not work for bmp files. It is triggering the error from this line:
if( !@getimagesize($_FILES["image"]['tmp_name']) ) $this->data['errors'][] = "File is not an image. Error Code #7102";
Any thoughts? I'm lost as to why its not working for bmp file. Granted I can always save to a different format in photoshop, but if I want to use it for a more public use it'd be nice to accept bmp too.

    Get rid of the '@' error suppressor and see if PHP is trying to throw any errors.

    While you're at it... get rid of the '@' error suppressor from your memory so you never use it again. 😉

      A PHP Error was encountered

      Severity: Warning

      Message: getimagesize() [function.getimagesize]: Filename cannot be empty

      Really confused now, since the code works flawlessly for other image types.

        Can you do a:

        print_r($_FILES);

        when you try uploading a BMP file and show us what the output is?

          when bmp:

          Array ( )
          1

          when jpg:

          Array ( [image] => Array ( [name] => army.jpg [type] => image/jpeg [tmp_name] => C:\wamp\tmp\php99E5.tmp [error] => 0 [size] => 1261808 ) )
          1

          using this line at the start of the function:

          echo "<pre>". print_r($_FILES) ."</pre>"; //bug testing
          

            What are your upload_max_filesize and post_max_size PHP directives set to?

              Oh... My... God... I fail so bad... thanks =D

              Is there anyway to test for that besides assuming it if the files array is empty?

                Derokorian wrote:

                Is there anyway to test for that besides assuming it if the files array is empty?

                There are one or two ways mentioned (I believe) in user comments on php.net - can't remember where (I tried looking for them briefly when I first saw the empty $_FILES array).

                Even if a form is submitted with an empty file upload field, you'll still get the appropriate entry in the $FILES array. I'm not sure what other conditions would cause an empty $FILES array, but it's possible that this is one way to check for the condition you're seeing.

                  Write a Reply...