Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

hyperpixel

upload de imagem de com segurança e resimensionamento

Recommended Posts

Estou garimpando a dias a web procurando um sistema assim mas não encontro nada, se tem segurança e aceita gif, png e jpg, não redimensiona, os com redimensionamento de imagem só trabalham com jpg, alguem sabe algo? onde consigo script que faça redimensionamento e suporte vários tipos de imagens.

 

Valeu

Compartilhar este post


Link para o post
Compartilhar em outros sites

mas como tinha falado já tinha testado este código o primeiro inclusive não rodou, mas você pode perceber que só aceita jpg o segundo trata vários arquivos mas não faz nada de redimensionamento ele aceita tamanho pré-determinado eu gostaria de redimensionamento mais de vários tipo de imagem além de jpg que creio ser padrão.

Compartilhar este post


Link para o post
Compartilhar em outros sites

dei uma olhada alem da pagina estar bagunçada erro de html etc vi uns 2, 3 cods mas não resolvem tem um de álbum de fotos etc ...mas a solução seria upload com redimensionamento que suporte os formatos png, gif além de jpg

Compartilhar este post


Link para o post
Compartilhar em outros sites

como exemplo tenho este aqui funcionando

 


<?php 
$idir = "../images/empresas/";   // Path To Images Directory 
$tdir = "../images/banners/";   // Path To Thumbnails Directory 
$twidth = "100";   // Maximum Width For Thumbnail Images 
$theight = "100";   // Maximum Height For Thumbnail Images 

if (!isset($_GET['subpage'])) {   // Image Upload Form Below ?> 
  <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>?subpage=upload" enctype="multipart/form-data">
    Enviar: 
    <input type="file" name="imagefile" class="form">
    <br /> 
  <input name="submit" type="submit" value="enviar" class="form">  
  <input type="reset" value="Limpar" class="form"> 
  </form> 
<?php
 } else  if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') {   // Uploading/Resizing Script 
  $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use 

  
  if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg" || $_FILES['imagefile']['type'] == "image/gif" || $_FILES['imagefile']['type'] == "image/png") { 
  
    $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php 
    $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location 
  
  if  ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location 
      print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image 
      $simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From 
      //$simg = imagecreatefromgif("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From 
      //$simg = imagecreatefrompng("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From 
	  
	  if($_FILES['imagefile']['type'] == "image/jpg"){
	  echo "image/jpg";
	  }
	  elseif($_FILES['imagefile']['type'] == "image/gif"){
	  echo "image/png";
	  }
	  else
	  {
	  echo "image/gif";
	  }
	  
	  $currwidth = imagesx($simg);   // Current Image Width 
      $currheight = imagesy($simg);   // Current Image Height 
      
	  if ($currheight > $currwidth) {   // If Height Is Greater Than Width 
         $zoom = $twidth / $currheight;   // Length Ratio For Width 
         $newheight = $theight;   // Height Is Equal To Max Height 
         $newwidth = $currwidth * $zoom;   // Creates The New Width 
      } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height) 
        $zoom = $twidth / $currwidth;   // Length Ratio For Height 
        $newwidth = $twidth;   // Width Is Equal To Max Width 
        $newheight = $currheight * $zoom;   // Creates The New Height 
      } 
	  
      $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail 
	  imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete 
      $palsize = ImageColorsTotal($simg); 
      for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image 
       $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used 
       ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use 
      } 
      imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image(So We Can Save It) 
      imagejpeg($dimg, "$tdir" . $url);   // Saving The Image 
	  imagegif($dimg, "$tdir" . $url);   // Saving The Image
      //imagepng($dimg, "$tdir" . $url);   // Saving The Image
	  imagedestroy($simg);   // Destroying The Temporary Image 
      imagedestroy($dimg);   // Destroying The Other Temporary Image 
      print 'Image thumbnail created successfully.'; // Resize successful 
    } else { 
      print '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed 
    } 
  } else { 
    print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';   // Error Message If Filetype Is Wrong 
    print $file_ext;   // Show The Invalid File's Extention 
    print '.</font>'; 
  } 
} ?>

Funciona direitinho gera miniatura etc mas so trabalha com jpg

Compartilhar este post


Link para o post
Compartilhar em outros sites

Sou meio leigo em PHP mas nesse código se você pegar essa linha que esta como comentario

 

//$simg = imagecreatefrompng("$idir" . $url);   // Make A New Temporary

 

e deixar assim

 

$simg = imagecreatefrompng("$idir" . $url);   // Make A New Temporary

 

será que nao funciona com png tambem?

Compartilhar este post


Link para o post
Compartilhar em outros sites

achei um que rodou só adaptar:

<?php 

error_reporting(0);

 

$change="";

$abc="";

 

 

define ("MAX_SIZE","400");

function getExtension($str) {

$i = strrpos($str,".");

if (!$i) { return ""; }

$l = strlen($str) - $i;

$ext = substr($str,$i+1,$l);

return $ext;

}

 

$errors=0;

 

if($_SERVER["REQUEST_METHOD"] == "POST")

{

$image =$_FILES["file"]["name"];

$uploadedfile = $_FILES['file']['tmp_name'];

 

 

if ($image)

{

 

$filename = stripslashes($_FILES['file']['name']);

 

$extension = getExtension($filename);

$extension = strtolower($extension);

 

 

if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))

{

 

$change='<div class="msgdiv">Unknown Image extension </div> ';

$errors=1;

}

else

{

 

$size=filesize($_FILES['file']['tmp_name']);

 

 

if ($size > MAX_SIZE*1024)

{

$change='<div class="msgdiv">You have exceeded the size limit!</div> ';

$errors=1;

}

 

 

if($extension=="jpg" || $extension=="jpeg" )

{

$uploadedfile = $_FILES['file']['tmp_name'];

$src = imagecreatefromjpeg($uploadedfile);

 

}

else if($extension=="png")

{

$uploadedfile = $_FILES['file']['tmp_name'];

$src = imagecreatefrompng($uploadedfile);

 

}

else

{

$src = imagecreatefromgif($uploadedfile);

}

 

echo $scr;

 

list($width,$height)=getimagesize($uploadedfile);

 

 

$newwidth=300;

$newheight=($height/$width)*$newwidth;

$tmp=imagecreatetruecolor($newwidth,$newheight);

 

 

$newwidth1=100;

$newheight1=($height/$width)*$newwidth1;

$tmp1=imagecreatetruecolor($newwidth1,$newheight1);

 

imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

 

imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);

 

 

$filename = "img/". $_FILES['file']['name'];

 

$filename1 = "img/small". $_FILES['file']['name'];

 

 

 

imagejpeg($tmp,$filename,100);

 

imagejpeg($tmp1,$filename1,100);

 

imagedestroy($src);

imagedestroy($tmp);

imagedestroy($tmp1);

}}

 

}

 

//If no errors registred, print the success message

if(isset($_POST['Submit']) && !$errors)

{

 

// mysql_query("update {$prefix}users set img='$big',img_small='$small' where user_id='$user'");

$change=' <div class="msgdiv">Image Uploaded Successfully!</div>';

}

 

?>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head>

<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">

<meta content="en-us" http-equiv="Content-Language">

 

<title>picture demo</title>

 

<link href="file:///C|/Documents and Settings/HWJobs/Configurações locais/Temporary Internet Files/Content.IE5/79V8OG8R/.css" media="screen, projection" rel="stylesheet" type="text/css">

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>

<script type="text/javascript" src="file:///C|/Documents and Settings/HWJobs/Configurações locais/Temporary Internet Files/Content.IE5/79V8OG8R/js/jquery_002.js"></script>

<script type="text/javascript" src="file:///C|/Documents and Settings/HWJobs/Configurações locais/Temporary Internet Files/Content.IE5/79V8OG8R/js/displaymsg.js"></script>

<script type="text/javascript" src="file:///C|/Documents and Settings/HWJobs/Configurações locais/Temporary Internet Files/Content.IE5/79V8OG8R/js/ajaxdelete.js"></script>

 

 

<style type="text/css">

.help

{

font-size:11px; color:#006600;

}

body {

color: #000000;

background-color:#999999 ;

background:#999999 url(<?php echo $user_row['img_src']; ?>) fixed repeat top left;

 

 

font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;

 

}

.msgdiv{

width:759px;

padding-top:8px;

padding-bottom:8px;

background-color: #fff;

font-weight:bold;

font-size:18px;-moz-border-radius: 6px;-webkit-border-radius: 6px;

}

#container{width:763px;margin:0 auto;padding:3px 0;text-align:left;position:relative; -moz-border-radius: 6px;-webkit-border-radius: 6px; background-color:#FFFFFF }

</style>

 

</head><body>

<div align="center" id="err">

<?php echo $change; ?> </div>

<div id="space"></div>

 

 

 

 

 

<div id="container" >

 

<div id="con">

 

 

 

<table width="502" cellpadding="0" cellspacing="0" id="main">

<tbody>

<tr>

<td width="500" height="238" valign="top" id="main_right">

 

<div id="posts">

    <img src="<?php echo $filename; ?>" />     <img src="<?php echo $filename1; ?>" />

<form method="post" action="" enctype="multipart/form-data" name="form1">

<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">

<tr><Td style="height:25px"> </Td></tr>

<tr>

<td width="150"><div align="right" class="titles">Picture

: </div></td>

<td width="350" align="left">

<div align="left">

<input size="25" name="file" type="file" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10pt" class="box"/>

 

</div></td>

 

</tr>

<tr><Td></Td>

<Td valign="top" height="35px" class="help">Image maximum size <b>400 </b>kb</span></Td>

</tr>

<tr><Td></Td><Td valign="top" height="35px"><input type="submit" id="mybut" value=" Upload " name="Submit"/></Td></tr>

<tr>

<td width="200"> </td>

<td width="200"><table width="200" border="0" cellspacing="0" cellpadding="0">

<tr>

<td width="200" align="center"><div align="left"></div></td>

<td width="100"> </td>

</tr>

</table></td>

</tr>

</table>

</form>

 

 

 

 

</div>

 

 

 

 

</td>

 

</tr>

</tbody>

</table>

 

 

 

 

</div>

 

</div>

 

 

 

</body></html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.