判断上传文件格式的问题 PHP
本帖最后由 Unbekannt 于 2009-3-17 14:39 编辑substr()这样不能判断么???或者别的方法有什么呢。。。
俄~~~我觉得这个问题好像很弱智。。。{:4_280:}
===============================================
function upload($file_info,$path,$max_file_size)
{
extract($file_info);
if($size==0)
{
$result['errcode'] = "zero";
return $result;
}
$a = pathinfo($name);
$ext = strtolower($a['extension']);
$result = array();
if(substr($type,0,3)!='pdf')
{
$result['errcode'] = "type_erro";
return $result;
}
if($size>$max_file_size)
{
$result['errcode'] = "size_erro";
return $result;
}
$f_name = date(dmYHis).".".$ext;
$sub_jpath = date(dmY)."/";
$path = $path.$sub_path;
$target = $path.$f_name;
$i = 1;
while(file_exists($target))
{
$f_name = date(dmYHis).($i++).".".$ext;
$target = $path.$f_name;
}
if(!file_exists(target))
{
mkdirsByPath(dirname($target));
}
$result['errcode'] = move_uploaded_file($tmp_name,$target);
$result['file_name'] = $sub_path.$f_name;
$result['size'] = $size;
$result['type'] = $type;
return $result;
} substr($type,0,3)!='pdf' ? woher kommt $type?
oder substr($ext,0,3).
Vorschlag:
if (strcasecmp($ext , 'pdf') == 0)
return true; substr($type,0,3)!='pdf' ? woher kommt $type?
oder substr($ext,0,3).
Vorschlag:
if (strcasecmp($ext , 'pdf') == 0)
return true;
cyhou 发表于 2009-3-17 16:25 http://www.dolc.de/forum/images/common/back.gif
啊~~~多谢阿。。。总是犯这种低级错误。。。
页:
[1]