Προς το περιεχόμενο

file attachment μέσα σε php φόρμα


varemarious

Προτεινόμενες αναρτήσεις

Δημοσ.

>
//Determine mime type
$pos = strrpos($_FILES['attachment']['name'], ".");
$ext = substr($_FILES['attachment']['name'], $pos+1, (strlen($_FILES['attachment']['name'])-$pos+1));

if($ext == "zip") { // Ορίζουμε τα accepted file types (zip, pdf, doc κλπ...)
   $mime_type = "application/zip";
}
elseif($ext == "pdf") { // Entaxei, auto mporei na ginei kai me switch alla you get the point...
   $mime_type = "application/pdf";
}
elseif($ext == "doc" || $ext == "docx") {
   $mime_type = "application/msword";
}
elseif($ext == "JPG" || $ext == "jpg" || $ext == "JPEG" || $ext == "jpeg") {
   $mime_type = "image/jpeg";
}
elseif($ext == "gif" || $ext == "GIF") {
   $mime_type = "image/gif";
}
else {
   exit("Error: Wrong file type!");
}

Αυτο δεν χρειάζεται λογικά. Το $_FILES["file"]["type"] περιέχει από μόνο του το mime type.

 

Από το http://www.php.net/manual/en/features.file-upload.post-method.php

$_FILES['userfile']['type']

 

The mime type of the file, if the browser provided this information. An example would be "image/gif".

Αρχειοθετημένο

Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.

  • Δημιουργία νέου...