Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] walidacja po typie mime
hhg
post
Post #1





Grupa: Zarejestrowani
Postów: 316
Pomógł: 0
Dołączył: 5.07.2006

Ostrzeżenie: (0%)
-----


piszę walidacje do uploadowanych plikow, i m.in sprawdzam typ mime takiego pliku. Mam wpuszczac tylko .xls, .doc, i pare innych. Niestety cos takiego:

  1. <?php
  2. if (
  3. $_FILES[$pointer]['type'] !== 'application/pdf' &&
  4. $_FILES[$pointer]['type'] !== 'application/msword' &&
  5. $_FILES[$pointer]['type'] !== 'application/vnd.ms-excel' &&
  6. $_FILES[$pointer]['type'] !== 'drawing/x-dwf' &&
  7. $_FILES[$pointer]['type'] !== 'model/vnd.dwf' &&
  8. $_FILES[$pointer]['type'] !== 'application/acad' &&
  9. $_FILES[$pointer]['type'] !== 'image/vnd.dwg' &&
  10. $_FILES[$pointer]['type'] !== 'image/x-dwg'
  11. ) {
  12. return new Notice(FALSE,'VALIDATE_UPLOADED_WRONG_FILE_FORMAT');
  13. }
  14. ?>


nie pozwala na jednym kompie wpuścic pliku .xls i .doc a na drugim pozwala!! nie rozumiem dlaczego
czy macie jakies pomysly dlaczego tak się dzieje?

z gory dzieki za pomoc
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
piotrekkr
post
Post #2





Grupa: Zarejestrowani
Postów: 386
Pomógł: 25
Dołączył: 28.09.2005

Ostrzeżenie: (0%)
-----


To z manuala :
Cytat
$_FILES['userfile']['type']

The mime type of the file, if the browser provided this information. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore don't take its value for granted.

Nie powinno sie brac tego za bardzo wiarygodna informacje o typie mime bo jest ona sprawdzana jedynie po stronie przegladarki a ja mozna oszukac.
Kiedys tez myslalem o walidacji przez typ mime i doszedlem do tego: http://pl2.php.net/manual/pl/ref.fileinfo.php. Niestety nie na kazdym hostingu jest to rozszerzenie :/ A co do typow mime dokumentow to w necie poszperalem troche i znalazlem takie typy:
Kod
$allowed_mime_types = array (
                
                //images
                'image/bmp',
                'image/gif',
                'image/jpeg',
                'image/pjpeg',
                'image/png',
                'image/x-png',
                'image/tiff',
                'image/x-tiff',
                'image/x-windows-bmp',
                'image/vnd.djvu',
                'image/svg+xml',
                
                //documents
                'text/plain',
                'application/msword',
                'application/vnd.ms-powerpoint',
                'application/postscript',
                'text/sgml',
                'application/x-latex',
                'application/mspowerpoint',
                'text/rtf',
                'text/richtext',
                'application/vnd.ms-excel',
                'application/pdf',
                'application/postscript',
                'text/xml',
                'application/x-dvi',
                'application/vnd.oasis.opendocument.text',
                'application/vnd.oasis.opendocument.text-template',
                'application/vnd.oasis.opendocument.presentation',
                'application/vnd.oasis.opendocument.presentation-template',
                'application/vnd.oasis.opendocument.graphics',
                'application/vnd.oasis.opendocument.graphics-template',
                'application/vnd.oasis.opendocument.spreadsheet',
                'application/vnd.oasis.opendocument.spreadsheet-template',
                'application/vnd.oasis.opendocument.chart',
                'application/vnd.oasis.opendocument.formula',
                'application/vnd.oasis.opendocument.database',
                'application/vnd.oasis.opendocument.image',
                'application/vnd.sun.xml.writer',
                'application/vnd.sun.xml.writer.template',
                'application/vnd.sun.xml.calc',
                'application/vnd.sun.xml.calc.template',
                'application/vnd.sun.xml.draw',
                'application/vnd.sun.xml.draw.template',
                'application/vnd.sun.xml.impress',
                'application/vnd.sun.xml.impress.template',
                'application/vnd.sun.xml.writer.global',
                'application/vnd.sun.xml.math',
                'application/vnd.stardivision.writer',
                'application/vnd.stardivision.writer-global',
                'application/vnd.stardivision.calc',
                'application/vnd.stardivision.draw',
                'application/vnd.stardivision.impress',
                'application/vnd.stardivision.impress-packed',
                'application/vnd.stardivision.math',
                'application/vnd.stardivision.chart'
            );

W czesci documents sa tez uwzglednione typy mime staroffice office i openoffice. Jak znajdziesz jeszcze jakies inne to napisz (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Ten post edytował piotrekkr 21.08.2007, 22:19:19
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 8.10.2025 - 01:55