Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Chrome e FF funciona certinho
mais no IE8 não, alguem sabe pq?
segue e codigo:
<?php
if(isset($_POST['acao']) && $_POST['acao'] == 'cadastrar'){
$foto = $_FILES['foto'];
if($foto['type'] == 'image/jpeg'){
require("red_imgs/funcao/funcao_upload_onibus.php");
$name = md5(uniqid(rand(), true)).".jpg";
Redimensionar($foto, $name, 150, "red_imgs/imgP");
}
}
?>
form:
<form method="post" action="" enctype="multipart/form-data">
<table class="tbl_prova" border="0">
<tr>
<td><strong>Titulo:</strong></td>
<td><label>
<input style="background:#3297fd; border:2px solid #000; color:#FFF;" type="text" name="nome_onibus" id="nome_onibus" />
</label></td>
</tr>
<tr>
<td><strong>Foto:</strong></td>
<td><input style="background:#3297fd; border:2px solid #000; color:#FFF; padding:10px;" type="file" name="foto" /></td>
</tr>
<tr>
<td>
<label><strong>Link</strong></label><br />
<label><strong>Exclusivo</strong></label></td>
<td><input style="background:#3297fd; border:2px solid #000; color:#FFF;" type="text" name="link_bus" id="link_bus" /></td>
</tr>
<tr>
<td> </td>
<td><input class="bto_prova" type="submit" value="Enviar" />
<input type="hidden" name="acao" value="cadastrar" /></td>
</tr>
</table>
</form>
Funcao:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php function Redimensionar($imagem, $name, $largura, $pasta){
$img = imagecreatefromjpeg($imagem['tmp_name']);
$x = imagesx($img);
$y = imagesy($img);
$altura = ($largura * $y)/$x;
$nova = imagecreatetruecolor($largura, $altura);
imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura, $altura, $x, $y);
imagejpeg($nova, "$pasta/$name");
imagedestroy($img);
imagedestroy($nova);
//faz o upload da imagem grande
$foto2 = $_FILES['foto'];
$upload = move_uploaded_file($foto2['tmp_name'], "red_imgs/imgG/".$name);
if($upload){
include "config.php";
$nome = $_POST['nome_onibus'];
$link_bus = $_POST['link_bus'];
$sql = mysql_query("INSERT INTO onibus (nome_bus, imgG, imgP, link_bus) VALUES('$nome', '$name', '$name', '$link_bus')") or die(mysql_error);
}
if($sql){
echo "<center>
<div style='border:2px solid #060; background:#0F3; width:500px;'>
<a href='cad_onibus.php'>
<img style='float:right; border:0;' src='imgs/fechaar.png' width='16' height='16' />
</a>
<center><img src='imgs/sucesso.png' width='24' height='24' />
<label>Onibus cadastrado com Sucesso!</label></center>
</div>
</center>";}else{ <center>
<div style='border:2px solid #F00; background:#C00; width:500px;'>
<a href='cad_onibus.php'>
<img style='float:right; border:0;' src='imgs/fechaar.png' width='16' height='16' />
</a>
<center><img src='imgs/erro.png' width='24' height='24' />
<label>Erro ao Cadastrar o Onibus...</label></center>
</div>
</center>";}
return $name;
}
?>Carregando comentários...