When I upload a file in PHP I am getting the wrong type for xlsx files.

It is telling me the type is a file name

Array (
[name] => report.xlsx
[type] => /folder/files/report/april_2013.xlsx
[tmp_name] => E:\path\to\temp\folder\phpCD1B.tmp
[error] => 0
[size] => 12433
)

Any ideas?

Hi

The code I am using is

view/display file

<form enctype="multipart/form-data" method="POST" action="update_comp.php" name="myform2">
<label>Upload Files ( PDF,CSV or EXCEL only ) </label>
<input type="file" name="file">
</form>

File update_comp.php

include ("filesFunctions.php");
if(isset($_FILES["file"])){$file = $_FILES["file"]; print_r($file);exit;
$upload = new filesFunctions();$id = $upload->uploadFiles($file,'dairy');

}

the print_r() statement prints

Array (
[name] => report.xlsx
[type] => /folder/files/report/april_2013.xlsx
[tmp_name] => E:\folder\to\temp\php5ACD.tmp
[error] => 0
[size] => 12433
)

Please note this only happens to xlsx files all other files work fine

The type key provides the MIME type of the file but this information is provided by the browser. As such:

This mime type is however not checked on the PHP side and therefore don't take its value for granted.

However, it's worth nothing that the $_FILES superglobal is by no means read-only. Like other superglobals, your PHP code can overwrite it:$_FILES['file']['type'] = 'Lorem ipsum dolor sit amet';

Assuming that you aren't fiddling with \$_FILES, the first obvious troubleshooting step is to fire your browser's debugger tools and inspect the POST data it sends. If that's the source of the string, you can forget about PHP.

I don't know what your browser is. In Google Chrome (in other browsers similar instructions apply) you must open the upload form, hit F12 and then click on "Network":

When you pick a file and submit the form, you'll see the request:

Expand the node and you'll see the data (application/vnd.openxmlformats-officedocument.spreadsheetml.sheet in this case):

This MIME type is normally configured by the Microsoft Office installer. If yours contains /folder/files/report/april_2013.xlsx you might need to repair or reinstall.