A cópia do código é a seguinte:
var imgobj = new Image (); // Crie um objeto de imagem
var allImgext = ". jpg | .jpeg | .gif | .bmp | .png |" // Todos os tipos de formato de imagem
Var FileObj, imgfilesize, imgwidth, imgheight, fileExt, errmsg, filemsg, hascheked, isImg // atributos relacionados à imagem variável global
// a seguir são as variáveis limite
var allowext = ". jpg | .gif | .doc | .txt |" // O tipo de arquivo permitido ser carregado? Para ilimitado, adicione um "|" até a letra minúscula após cada extensão.
var allowImgFilesize = 70; // O tamanho do arquivo de imagem carregado permitido é 0 ilimitado: KB
var allowImgWidth = 500; // A largura da imagem carregada é ilimitada: px (pixels)
var allowImghEight = 500; // A altura da imagem carregada permitida? É unidade ilimitada: px (pixels)
Haschecked = false;
Função CheckProperty (OBJ) // Detecção de propriedades da imagem
{
FILEOBJ = OBJ;
if (errmsg! = "") // verifique se é o arquivo de imagem correto e retorne a mensagem de erro e redefinir
{
Showmsg (errmsg, false);
retornar falso; //Retornar
}
Imgfilesize = math.round (imgobj.filesize/1024*100)/100; // obtenha o tamanho do arquivo de imagem
Imgwidth = imgobj.width; // Obtenha a largura da imagem
Imgheight = imgobj.Height; // Obtenha a altura da imagem
FILEMSG = "/n Tamanho da imagem:"+imgwidth+"*"+imghight+"px";
Filemsg = filemsg+"/n Tamanho do arquivo de imagem:"+imgfilesize+"kb";
Filemsg = filemsg+"/n Extensão do arquivo de imagem:"+fileExt;
if (allowImgwidth! = 0 && allowImgwidth <imgwidth)
Errmsg = errmsg+"/nA largura da imagem excede o limite. Faça o upload de um arquivo com uma largura menor que"+allowImgWidth+"px, a largura da imagem atual é"+imgwidth+"px;
if (allowImghEight! = 0 && allowImghEight <imghight)
Errmsg = errmsg+"/nA altura da imagem excede o limite. Faça o upload de um arquivo com uma altura menor que"+allowImgHeight+"px, a altura da imagem atual é"+imghight+"px";
if (allowImgFilesize! = 0 && allowImgFilesize <imgfilesize)
Errmsg = errmsg+"/nO tamanho do arquivo de imagem excede o limite. Por favor, carregue um arquivo menor que"+allowImgFilesize+"kb, o tamanho atual do arquivo é"+imgfilesize+"kb;
if (errmsg! = "") showmsg (errmsg, false);
else showmsg (filemsg, true);
}
Imgobj.onerror = function () {errmsg = '/nA imagem do formato está incorreto ou a imagem está corrompida!'}
função showmsg (msg, tf) // Mostrar mensagem imediata tf = true Show Informações do arquivo tf = false mostrar mensagem de erro MSG-Informação Conteúdo
{
msg = msg.replace ("/n", "<li>");
msg = msg.replace (// n/gi, "<li>");
se (! tf)
{
FILEOBJ.OUTERHTML = FILEOBJ.OUTERHTML;
Msglist.innerhtml = msg;
Haschecked = false;
}outro{
if (isImg) visualizeimg.innerhtml = "<img src = '"+imgobj.src+"' width = '60 'altura = '60'>";
caso contrário, visualizeimg.innerhtml = "arquivo não de imagem";
Msglist.innerhtml = msg;
Haschecked = true;
}
}
função checkext (obj)
{
Errmsg = "";
Filemsg = "";
FILEOBJ = OBJ;
Isimg = false;
Haschecked = false;
Previewimg.innerhtml = "área de visualização";
if (obj.value == "") retorna false;
Msglist.innerhtml = "Processamento de informações do arquivo ...";
FileExt = obj.value.substr (obj.value.lastIndexof (".")). ToLowerCase ();
if (allowext! = 0 && allowext.indexof (fileExt+"|") ==-1) // julga se o upload é permitido para o tipo de arquivo
{
Errmsg = "/NTE tipo de arquivo não pode ser carregado. Faça o upload de um arquivo do tipo"+allowext+", o tipo de arquivo atual é"+fileExt;
Showmsg (errmsg, false);
retornar falso;
}
if (AllImgext.IndexOF (FILEEXT+"|")! =-1) // Se o arquivo de imagem, o processamento de informações da imagem será realizado
{
Isimg = true;
Imgobj.src = obj.value;
alerta (imgobj.src);
alerta (Math.Round (imgobj.Filesize/1024*100)/100);
Checkproperty (OBJ);
retornar falso;
}outro{
FILEMSG = "/NFILE Extensão:"+FILEEXT;
Showmsg (filemsg, true);
}
}