多图片上传,在网上找了代码,因为想要那种和flash交互的,用起来很方便。
看了后台上传的代码,他取图片后缀名的时候,用的是strrchr($name,'.');这个方法,我觉得这个危险系数比较大,于是想用$_FILES["image"]["type"]这个来换掉,但是,换过来我输出一看,[type] => application/octet-stream按理说,应该是[type] => image/jpeg 的啊?不明白为啥

解决方案 »

  1.   

    show the all of codes ...
      

  2.   


    <?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 '';
    }
    }
    ?>
      

  3.   

    $_FILES['userfile']['type']
    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.
      

  4.   

    look the html , <form action="" method="post" enctype="multipart/form-data">, maybe that is difference in the flash , you can check it out.