dpnfjx755573 2009-12-16 21:42
浏览 48
已采纳

PHP图像文件上传大写扩展问题

I've a php script to deal with uploaded images.

it works fine if i upload a file like file.jpg.

But i got trouble if i try to upload file.JPG. Even if its the same file renamed.

The code:

if(isset($_FILES["arq"])){ 
    @getimagesize($_FILES['arq']['tmp_name']) or $err=5; 
    ($_FILES['arq']['error']==0) or $err=$_FILES['arq']['error'];


    if ($err==0){
        $dir = "./img/".$_SESSION['estudante']."/";
        if (!is_dir($dir)){mkdir($dir);}
        $filename = substr(md5(uniqid(rand(), true)),0,20) . ".";
        $filename .= pathinfo($_FILES["arq"]["name"], PATHINFO_EXTENSION);
        $fotourl = $dir . basename($filename);//$_FILES["arq"]["name"]);
        move_uploaded_file($_FILES["arq"]["tmp_name"], $fotourl);
        //resize e cira thumbnails
        resizeimg($fotourl, 320,204);   //editfoto
        resizeimg($fotourl, 137,87);    //album
        resizeimg($fotourl, 200,0);     //home
        resizeimg($fotourl, 148,0);     //perfil
        resizeimg($fotourl, 60,60);     //thumbnail
        resizeimg($fotourl, 100,0);     //iframe perfil
        resizeimg($fotourl, 530, 530);  //slide
        resizeimg($fotourl, 330, 0);    //i slide
        //registra no BD
        $sql="INSERT INTO fotos (estudante, url) VALUES ('".$_SESSION['estudante']."', '$fotourl')";
        mysql_query($sql);
        //retorna o id da foto
        $fotoid=mysql_insert_id();
        //notifica adms somente
        $sql="select estudante from administradores";
        $adms=mysql_query($sql);
        while ($ar=mysql_fetch_assoc($adms)){
            $msg="O usuário <a href=\"perfil.php?id=$_SESSION[estudante]\">".nomeapelido($_SESSION['estudante'])."</a> inseriu uma nova <a href='fotoslide.php?fotoid=$fotoid'>imagem</a>.";
            $sql="insert into mensagens (msgde, msgpara, msgmsg) values (5, $ar[estudante], '$msg')";   // 5=cadastro do 'user' sistema
            mysql_query($sql);
            //echo "$sql
";
        }
        mysql_free_result($adms);
    }
}
  • 写回答

1条回答 默认 最新

  • donglu3184 2009-12-17 06:30
    关注

    You should be able to just rename the extension to lower case when you move the file. If it's really important to preserve the actual case of the extension of the initial file, it is easy enough to store it in a variable before strtolower is applied, pass it into the imgresize function, and use that for the extension when the resized img is saved.

    $filename .= strtolower(pathinfo($_FILES["arq"]["name"], PATHINFO_EXTENSION));
    $fotourl = $dir . basename($filename);//$_FILES["arq"]["name"]);
    move_uploaded_file($_FILES["arq"]["tmp_name"], $fotourl);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图