php文件上传无效,Mime验证php文件上传无效

我正在尝试在将文件上传到数据库之前验证文件的mime类型.但是,我没有从我的程序中获得任何输出.有人可以帮我这个吗?提前致谢 :)

表单句柄代码(handleUpload.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";

}

}

}

?>

函数和数据库操作代码(upload.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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值