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); 开发者_如何学Go //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\n";
}
mysql_free_result($adms);
}
}
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);
精彩评论