Php file Upload judgment file type solution

Source: Internet
Author: User
Tags php file upload
Php uploads a file to determine the file type. I want to upload a csv file now. how can I determine in php that the file type is csv? Note: in addition to determining the extension, how can we determine the extension ?? ------ Solution ------------------ $ _ FILES [& quot; file & quot;] [& quot; type & quot;] ------ php uploads a file to determine the file type
I want to upload a csv file now,
In php, how does one determine that the file type is csv?

Note:
In addition to determining the extension, what else can be used to determine the segment ??

------ Solution --------------------
$ _ FILES ["file"] ["type"]
------ Solution --------------------
Discussion

$ _ FILES ["file"] ["type"]

------ Solution --------------------
Learning !!!!!!!!!!!!!!!
------ Solution --------------------
The landlord has to complicate simple things. No way!
------ Solution --------------------
A good way to spread it online
PHP code
Function ftype ($ filename) {$ file = fopen ($ filename, "rb"); $ bin = fread ($ file, 2 ); // read-only 2-byte fclose ($ file); $ strInfo = @ unpack ("C2chars", $ bin); $ typeCode = intval ($ strInfo ['chars1']. $ strInfo ['chars2 ']); $ fileType = ''; switch ($ typeCode) {case 7790: $ fileType = 'exe'; break; case 7784: $ fileType = 'midi '; break; case 8297: $ fileType = 'rar'; break; case 255216: $ fileType = 'jpg '; break; case 7173: $ fileType = 'GIF'; break; case 6677: $ fileType = 'bmp '; break; case 13780: $ fileType = 'PNG'; break; default: $ fileType = 'unknown ';} return $ fileType ;}
------ Solution --------------------
I think the method on the eighth floor has been used to determine to the greatest extent possible. according to the landlord's meaning, how does the uploaded file determine whether the content is in csv format (do not trust the extension ), you can only obtain the content in the file and determine whether it is a csv file based on the content in the file. However, this method must be implemented in the background, that is, the file has already been uploaded, it is useless to determine after uploading. Therefore, I personally think that there is no good solution to determine the content format without uploading.
------ Solution --------------------
Discussion

I mean, the csv file is not used. are the files separated?

Aa, bb, cc, dd
Ee, ff, gg, hh

Files like this
According to the statement on the eighth floor, the typeCode of this file is 131112
However

Aa, "B
B ", cc, dd
Ee, ff, gg, hh

This is also the correct csv format, but the typeCode of this file is 105105
......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.