Jump to content

visualizar imagem em PHP


manuel dias

Recommended Posts

<html>
<head>
<title>Script de Fotos</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="/includes/estilos/azul.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style4 {
color: #FF0000;
font-weight: bold;
font-size: 10px;
}
.style5 {font-size: 10px}
-->
</style>
<script>
var escondido = 0;

function preview()
{
img = document.getElementById('img');
if(escondido)
{
esc.innerHTML = '<a href="javascript:;" class="menu style5" onclick="preview()">(esconder)</a><br><img onload="getSize()" width="150" src="'+escondido+'" name="img" id="img">';
escondido = 0;
}
else
{
escondido = img.src;
img.src = '';
esc.innerHTML = '<a href="javascript:;" class="menu style5" onclick="preview()">(mostrar)</a><br><img onload="getSize()" src="1px.gif" width="1" height="1" name="img" id="img">';
}
}

function find_array(arr,str)
{
for(i=0; arr.length>i; i++)
{
if(arr[i] == str) return 1;
}
return 0;
}

function verificaFoto()
{
var obj = document.getElementById('file');
var v = obj.value;
var extencao=v.substr(v.length - 4).toLowerCase();
var extPerm = new Array(".gif",".jpg",".png","jpeg",".GIF",".JPG",".PNG","JPEG");
var img = document.getElementById('img');
img.src = "file://"+obj.value;
img.width = 200;
if(!find_array(extPerm,extencao))
{ 
alert("Só são permitidas fotos nos formatos GIF, PNG e JPG/JPEG");
obj.value = "";
esc.innerHTML = '<br><img onload="getSize()" src="1px.gif" width="1" height="1" name="img" id="img">';
return 0;
}

escondido = img.src;
if(escondido) preview(); 
}

function getSize()
{
if(document.getElementById('img').fileSize > 200000)
{
alert("A foto não pode ter mais de 200 KB.");
obj.value = "";
esc.innerHTML = '<br><img onload="getSize()" src="1px.gif" width="1" height="1" name="img" id="img">';

return 0;
}
return 1;
}





var escondido1 = 0;

function preview1()
{
img1 = document.getElementById('img1');
if(escondido1)
{
esc1.innerHTML = '<a href="javascript:;" class="menu style5" onclick="preview1()">(esconder)</a><br><img onload="getSize1()" width="150" src="'+escondido1+'" name="img1" id="img1">';
escondido1 = 0;
}
else
{
escondido1 = img1.src;
img1.src = '';
esc1.innerHTML = '<a href="javascript:;" class="menu style5" onclick="preview1()">(mostrar)</a><br><img1 onload="getSize1()" src="1px.gif" width="1" height="1" name="img1" id="img1">';
}
}

function find_array1(arr,str)
{
for(i=0; arr.length>i; i++)
{
if(arr[i] == str) return 1;
}
return 0;
}

</script>

<script language="JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
  document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
</script>
<FORM METHOD="POST" ACTION="" name="sistema"> 
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#FFFFFF" text="#000000" link="#000000" vlink="#000000" alink="#666666">


<div id="Layer1" style="position:absolute; left:40%; top:-350px; width:300px; height:150px; z-index:1"> 
<table width="300" border="0" cellpadding="0" cellspacing="0" class="tabelaborda">
  <tr> 
    <td height="20" colspan="3" class="tabelatopo"><font face="Tahoma" size="1"> AGUARDE...</font></td>
  </tr>
  <tr> 
    <td height="10" colspan="3"><font face="Tahoma" size="1"><img src="1px.gif" width="1" height="1"></font></td>
  </tr>
  <tr> 
    <td width="10" rowspan="2"> </td>
    <td width="280" align="center" valign="middle" class="verdana12"> 
      <div align="justify"><font face="Tahoma" size="1">Aguarde enquanto a foto 
        está sendo enviada. Isto pode levar alguns segundos. <strong>Não pare 
        este processo.</strong> </font></div>
    <td width="10" rowspan="2"> </td>
  </tr>
  <tr> 
    <td height="12" colspan="3" class="noticialink"><font face="Tahoma" size="1"><img src="1px.gif" width="1" height="1"></font></td>
  </tr>
</table>
</div>

 <hr size="1">
 <table width="212" border="1">
   <tr>
     <td width="510"><table width="204" border="0" cellpadding="0" cellspacing="5">
       <input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
       <tr>
         <td valign="top"><p class="texto"><b><font face="Tahoma" size="1">FOTO 1 :<br>
                     <input type="file" id="file" onChange="verificaFoto()" name="file" size="20"  />
         </font></b></p></td>
       </tr>
       <tr>
         <td valign="top" class="texto"><font face="Tahoma" size="1">Pré-visualização:
           <label id="esc"><br>
               <img src="1px.GIF" name="img" id="img" width="1" height="1"></label>
         </font></td>
       </tr>
     </table></td>
   </tr>
</table>
</form>
</body>
</html>
Edited by anolsi
Adicionado o geshi
Link to comment
Share on other sites

Mete o teu codigo num bloco de codigo:

[ code=html4strict ] ... [ /code ]

E faz uma pergunta ou comentario especifico 🙂

What have you tried?

Não respondo a dúvidas por PM

A minha bola de cristal está para compor; deve ficar pronta para a semana.

Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código!

Link to comment
Share on other sites

é a 2ª vez que estou a utilizar osite e na barra de ferramentas do editor avançado não tenho um botão contendo o símbolo "< >" de forma a por isto em blocos.

Com o codigo acima em HTML consigo verificar a imagem quando faço o upload, mas ao gravar em php a imagem não aparece. Alguèm me consegue ajudar?

Edited by manuel dias
Link to comment
Share on other sites

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>



<?php
$TARGET_PATH = "Users/madias/Downloads";

$Caminho_destino = $TARGET_PATH. basename ($_FILES ['uploadedfile'] ['name']);

if (move_uploaded_file ($_FILES ['uploadedfile'] ['tmp_name'], $TARGET_PATH)) {
echo "O arquivo". basename ($_FILES ['uploadedfile'] ['name']).
"Foi enviado";
}Else {
echo "Ocorreu um erro ao fazer o upload do arquivo, por favor, tente novamente!";
}
?>

Segui o exemplo o resultado foi: "Ocorreu um erro ao fazer o upload do arquivo, por favor, tente novamente!"

Não consigo perceber onde estou a falhar....

Edited by manuel dias
Link to comment
Share on other sites

<FORM METHOD="POST" ACTION="" name="sistema">
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#FFFFFF" text="#000000" link="#000000" vlink="#000000" alink="#666666">

</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#FFFFFF" text="#000000" link="#000000" vlink="#000000" alink="#666666">
<FORM METHOD="POST" ACTION="" name="sistema">

assim?!

*edited: reformat do texto

Edited by MoshMage

If all Else fails, use Else If;

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.