2015-07-28 22 views
5

Bir dosyanın mime türünü veritabanına yüklemeden önce doğrulamaya çalışıyorum. Ancak, programımdan çıktı almıyorum. Bununla ilgili biri bana yardım edebilir mi? Ben yazmadım çünkü önceden :)Php dosyası için Mime doğrulaması çalışma yükleniyor

Formu kolu kodu teşekkürler (handleUpload.php)

<?php 
    if (isset($_POST['submit'])) { 
     $Upload = new Upload(); 
     if (function_exists("check_doc_mime")) { 
      //validate MIME type 
      $validateMime = $Upload->check_doc_mime($_FILES['filename']['tmp_name']); 
      if (!$Upload->check_doc_mime($validateMime)) { 
       /* Not a MIME type we want on our site, stop here 
       * and return an error message, or just die(); */ 
       echo "Mime not what we want."; 
      } else { 
       echo "This is okay"; 
      } 
     } 
    } 
?> 

Fonksiyonlar ve veritabanı manipülasyon kodu (upload.php)

<?php 
    // If it's going to need the database, then it's 
    // probably smart to require it before we start. 
    require_once(LIB_PATH . DS . 'database.php'); 

    class Upload extends DatabaseObject { 

     protected static $table_name = "resume"; 
     protected static $db_fields = array('resume_id', 'individual_id', 'resume_title', 'file_type', 'file_size', 'upload_date', 'status', 'resume_data'); 
     public $resume_id; 
     public $individual_id; 
     public $resume_title; 
     public $file_type; 
     public $file_size; 
     public $upload_date; 
     public $status; 
     public $resume_data; 
     protected $destination; //so cannot be changed outside of class 

     function check_doc_mime($tmp_name) { 
      // MIME types: http://filext.com/faq/office_mime_types.php 
      $finfo = finfo_open(FILEINFO_MIME_TYPE); 
      $mtype = finfo_file($finfo, $tmp_name); 
      if($mtype == ("application/vnd.openxmlformats-officedocument.wordprocessingml.document") || 
      $mtype == ("application/vnd.ms-excel") || 
      $mtype == ("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") || 
      $mtype == ("application/vnd.ms-powerpoint") || 
      $mtype == ("application/vnd.openxmlformats-officedocument.presentationml.presentation") || 
      $mtype == ("application/pdf")) { 
      return TRUE; 
      } 
      else { 
      return FALSE; 
      } 
      finfo_close($finfo); 
     } 



     public function uploadResume($fileName, $tmpName, $fileSize, $fileType, $date){ 

      global $database; 

      $fp = fopen($tmpName, 'r'); 
      $content = fread($fp, filesize($tmpName)); 
      $content = addslashes($content); 
      fclose($fp); 

      if(!get_magic_quotes_gpc()) 
      { 
      $fileName = addslashes($fileName); 
      } 
      $sql = "INSERT INTO resume (resume_title, file_size, file_type, resume_data, status, individual_id) ". 
       "VALUES ('$title', '$fileSize', '$fileType', '$content', '1', '$id')"; 
      $database->query($sql); 
     } 



    } 

    $Upload = new Upload(); 
    $upload =& $Upload; 
?> 
+0

Bu konuda yeniyim ve ne demek istediğinizden emin değilim. "upload.php" üzerindeki işlev (check_doc_mime) {} ". Eğer değilse, nerede tanımlayacağımı lütfen öğrenebilir miyim? –

+0

@TinyGiant, "check_doc_mime" işlevinin nerede olduğunu soruyor. Bir yerlerde, 'function check_doc_mime ($ var) {code here}' işlevi gibi yazılmış bir işleve sahip olursunuz. Bu işlevin ne yaptığını görmeliyiz. – Rasclatt

+0

Nevermind, tamamen ikinci kod bloğunda olduğunu kaçırdı. Ama bu bir 'Upload' yöntemi. '$ Upload = new $ Upload();' $ Upload = new Upload(); 've' if (! Check_doc_mime ($ validateUser)) {'olmalıdır, eğer (! $ Upload-> check_doc_mime ($ validateUser))) {' –

cevap

2

çıkıyor ise benim ifadesi doğruysa. if (!$Upload->check_doc_mime($validateMime)) { değil if (!$validateMime) { olmalıdır.

İlgili konular