Re: cannot recognize $_FILES['UploadedFile']['type'];

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



After reading the documentation in more detail, this should not be server 
dependant. The browser is responsible for providing MIME type. So this 
depends on the browser, not the server you're running it on. 

What I would do is:
$e = explode(".", $_FILES['UploadedFile']['name']); // split by '.'
$extension = $e[count($e)-1]; // get last chunk

if ($extension == "html" || $extension == "htm") {
//	IT's a html file..
}

HTH 
-Micah 


On Sunday 21 August 2005 9:41 pm, Yui Hiroaki wrote:
> So How can I chage code and detect file type?
>
> Here is my code;
>
> ----------index.html--------------------
> <form method="post" action="document.php" enctype="multipart/form-data">
> <input type="hidden" name="MAX_FILE_SIZE" value="512000">
> <input type="file" name="UploadedFile" style="border: 1px solid;
> width:200px; height:20px; position:absolute;
>
> ---------------------------------------------
>
> -----------document.php--------------------
>
> $original_type = $_FILES['UploadedFile']['type'];
> -------------------------------------------
>
>
> Please teach me how I can detect file type...
>
>
> Regards,
> Yui
>
> Micah Stevens wrote:
> > Unix will look at the first few bytes of the file to determine type, and
> > does a much better job with the mimetype situation than windows in my
> > experience, but to give window's credit, it's not lying, the mimetype for
> > HTML is text/html I think.. it IS a text file..
> >
> > Windows has traditionally relied on the file extension to determine
> > type.. (.exe means it's executeable fore example) whereas unix uses a
> > more pragmatic method of looking at the first few bytes as I mentioned,
> > and also file permissions.. (there's an executeable bit for the file if
> > it's executeable)
> >
> > You'll need to parse the filename in windows it sounds like to me.
> > -Micah
> >
> > On Sunday 21 August 2005 8:48 pm, Yui Hiroaki wrote:
> >>I try to upload file from web. I use $_FILES['UploadedFile']['type'];
> >>It'file type is recognized by inix or linux enviroment. Now I use
> >>php on windows 2003 server. It does not recognize file type to up
> >>load file from web. I upload html, but $_FILES['UploadedFile']['type'];
> >>recognize as a text.
> >>
> >>
> >>Do please answer my wonder.
> >>
> >>
> >>Regards,
> >>Yui

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux