多图片上传,在网上找了代码,因为想要那种和flash交互的,用起来很方便。
看了后台上传的代码,他取图片后缀名的时候,用的是strrchr($name,'.');这个方法,我觉得这个危险系数比较大,于是想用$_FILES["image"]["type"]这个来换掉,但是,换过来我输出一看,[type] => application/octet-stream按理说,应该是[type] => image/jpeg 的啊?不明白为啥
看了后台上传的代码,他取图片后缀名的时候,用的是strrchr($name,'.');这个方法,我觉得这个危险系数比较大,于是想用$_FILES["image"]["type"]这个来换掉,但是,换过来我输出一看,[type] => application/octet-stream按理说,应该是[type] => image/jpeg 的啊?不明白为啥
解决方案 »
- 求一下总记录数,好分页,但是count(*) 要2秒,查询时间记录结果只要0.0044秒
- php有xdebug,js有什么工具可以查看已经执行的函数?
- 关于网站自动发短信的问题,谢谢
- 碰到个事儿,二维数组的,很有意思
- mysql administrator怎么连接mysql啊?
- 用phpeclipse 编辑*.php时 无法自动提示该怎么办??
- 哪位提供一个smartemplate使用行和列构建table的使用方法?
- 用php可以连接pop3的端口吗?
- 大家好,我在设计购物车是时,有一个清空购物车,我的思路是清空car这个数据库,但不知怎么写这个sql语句
- gd库
- 统计某时间范围内的数量
- 新年到了!!! 散分
<?php
// 注意:使用组件上传,不可以使用 $_FILES["Filedata"]["type"] 来判断文件类型
mb_http_input("utf-8");
mb_http_output("utf-8");
//require('./thumbnails.php');
//$type=filekzm($_FILES["Filedata"]["name"]); //原代码用的这个求出后缀名
$type=type($_FILES["Filedata"]["type"]); //这是我自己改的
echo '<pre>';
print_r($_FILES["Filedata"]);
if ((($type == ".gif") || ($type == ".png") || ($type == ".jpg")) && ($_FILES["Filedata"]["size"] < 200000))
{
if ($_FILES["Filedata"]["error"] > 0)
{
echo "返回错误: " . $_FILES["Filedata"]["error"] . "<br />";
}
else
{
echo "上传的文件: " . $_FILES["Filedata"]["name"] . "<br />";
echo "文件类型: " . $type . "<br />";
echo "文件大小: " . ($_FILES["Filedata"]["size"] / 1024) . " Kb<br />";
echo "临时文件: " . $_FILES["Filedata"]["tmp_name"] . "<br />";
if (file_exists( $_FILES["Filedata"]["name"]))
{
echo $_FILES["Filedata"]["name"] . " already exists. ";
}
else
{
$name = $_FILES["Filedata"]["name"];
move_uploaded_file($_FILES["Filedata"]["tmp_name"],$name);
echo "Stored in: " . $_FILES["Filedata"]["name"];
}
}
}
else
{
echo "上传失败,请检查文件类型和文件大小是否符合标准<br />文件类型:".$type.'<br />文件大小:'.($_FILES["Filedata"]["size"] / 1024) . " Kb";
}function type($type)
{
echo $type;
switch ($type)
{
case 'image/gif': $t = '.gif'; break;
case 'image/jpeg':$t = '.jpg'; break;
case 'image/pjpeg': $t = '.jpg'; break;
case 'image/png': $t = '.png'; break;
}
return $t;
}function filekzm($a)
{
$c=strrchr($a,'.');
if($c)
{
return $c;
}
else
{
return '';
}
}
?>
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.so, the flash upload the files by binary of application/octet-stream , in general, we use the post-method to upload the files, therefore, you feel it that is image/jpeg.you must change the type of upload in the flash if you want to get the image/jpeg and not modify others in the php.