Hi to all,
Here is my code, I want upload file which are only images. All images with jpg, JPG, jpeg, JPEG, gif are uploaded successfully except with bmp file.
Plz, help me to find out the prob. why my code is fail with bmp extension file.

//file-detail-complex.php
<?php
$title = $_POST['title'];
$image = $_FILES['file']['name'];
$ext = explode('.',$image);
$size = $_FILES['file']['size'];
$a=array("jpg","jpeg","JPG","JPEG","png","gif","GIF","bmp","BMP");
$submit = $_POST['submit'];
if((in_array($ext[1],$a)) && ($size<=20000) && !empty($submit))
{
	echo "File is correct!";
	echo "<br/>";
	echo "Image :".$image;
	echo "<br/>";
	echo "Extention :".$ext[1]; 
	echo "<br/>";
	echo "Size :".$size;
	echo "<br/>";
	if(file_exists("upload-img/" .$image))
	{
		echo "file already exist!";
	}
	else
	{
	$upload=move_uploaded_file($_FILES["file"]["tmp_name"], "upload-img/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload-img/" . $_FILES["file"]["name"];
	}
}
else 
{
	echo "Please check the extension and size of the file!";
	echo "<br/>";
}
?>
<body>
<form action="file-detail-complex.php" method="post" enctype="multipart/form-data">
Title:<input type="text" name="title" id="title" />
Image :<input type="file" name="file" id="file" />
<input type="submit" name="submit" value="submit" id="submit" />
</form>
</body>

Did you check if it is the file size that matters ?

if the bmp file's size is larger than 20,000 bytes, then according to my code, the error abt file size should be displayed. It also worked, but not with bmp extension. When i select bmp file, following ouput displays.

Please check the extension of the file!
File size is ok!
Image :project-view.bmp
Extention :bmp
Size :0
Stored in: upload-img/project-view.bmp

It also shows that file is uploaded, but in actual, folder doesn't contain bmp file.
What is the prob.?

Hi,
Enter the below line before if loop and say what it prints.
print_r($_FILES);

Thank you,
Prem

Good morning to all,
As per reply I put print_r($_FILES); before 'if' loop
Shows following o/p.

Array ( [file] => Array ( [name] => comment.bmp [type] => [tmp_name] => [error] => 1 => 0 ) ) File is correct!
Image :comment.bmp
Extention :bmp
Size :0
Stored in: upload-img/comment.bmp

That is, it shows error, but what is error. plz, guide again.

Thank you very much, but it is too critical to understand for me, bcoz i m very very new to the php. But I try to understand it. Can i ask again to u if i find any trouble while reading it?

That means "The uploaded file exceeds the upload_max_filesize directive in php.ini."

The following link will give you more insight on file upload errors

http://php.net/manual/en/features.file-upload.errors.php

Yes, that is fine...
You are getting that error coz the file size you are uploading exceeds the setting value of 'upload_max_filesize' in php.ini . By default this value will be set to 2M bytes. If you want to upload a file exceeding this size you will have to change that in php.ini .
Also look into the settings 'post_max_size' and other related ones.

Check the following link for more details

http://php.net/manual/en/ini.core.php

where should i find 'php.ini' file.

Yes, that is fine...
You are getting that error coz the file size you are uploading exceeds the setting value of 'upload_max_filesize' in php.ini . By default this value will be set to 2M bytes. If you want to upload a file exceeding this size you will have to change that in php.ini .
Also look into the settings 'post_max_size' and other related ones.

Check the following link for more details

http://php.net/manual/en/ini.core.php

Run the following script

<?php
phpinfo();
?>

The following show the path to php.ini file


Loaded Configuration File : ..path to php.ini file


Make changes to the settings and then restart your apache server for the change in settings to be effective.

u r genius! ur php knowledge is just amazing.

Very very thankds.

Run the following script

<?php
phpinfo();
?>

The following show the path to php.ini file


Loaded Configuration File : ..path to php.ini file


Make changes to the settings and then restart your apache server for the change in settings to be effective.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.