Problemas com sistema de fotos
Bom dia pessoal!
Estou com um problema no meu sistema de fotos.
A parte de fazer upload e de gravar os dados no
bd está ok, o problema é que criei uma função
para dimensionar a imagem, que deve ser 500X375
e a função não está funcionando, parece que os dados não
são passados pela função, ou sei lá o q!
Já tentei várias coisas mas nada resolve!
:huh:
Será q alguém consegue me ajudar!?
Este é o código:
PHP
<?php require_once('conecta.php'); ?> <?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (()) ? [addslashes](http://br.php.net/addslashes)($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? [intval](http://br.php.net/intval)($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . [doubleval](http://br.php.net/doubleval)($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if ([isset](http://br.php.net/isset)($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . [htmlentities](http://br.php.net/htmlentities)($_SERVER['QUERY_STRING']);
}
// Aqui, pegamos o nome e o nome temporário da imagem enviada.
$foto = $_FILES["foto_foto"]["name"];
$fotoTmp = $_FILES["foto_foto"]["tmp_name"];
$fotoSize = $_FILES["foto_foto"]["size"];
$fotoTipo = $_FILES["foto_foto"]["type"];
if (([isset](http://br.php.net/isset)($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
if($fotoSize >= "51200"){
$erro = ("Arquivo é maior que o permitido.");
}
if($erro != ""){
[echo](http://br.php.net/echo) "$erro";
}
else{
// Acrescentamos o campo: foto_data.
// Em VALUES, alteramos o primeiro %s por '$foto'; e acrescentamos o comando NOW().
[mysql_select_db](http://br.php.net/mysql_select_db)($database);
$query_rsUltimaFoto = "SELECT *, date_format(foto_data, '%d/%m/%Y') AS foto_data FROM w_floricultura ORDER BY foto_id DESC";
$rsUltimaFoto = [mysql_query](http://br.php.net/mysql_query)($query_rsUltimaFoto) or [die](http://br.php.net/die)([mysql_error](http://br.php.net/mysql_error)());
$row_rsUltimaFoto = [mysql_fetch_assoc](http://br.php.net/mysql_fetch_assoc)($rsUltimaFoto);
$totalRows_rsUltimaFoto = [mysql_num_rows](http://br.php.net/mysql_num_rows)($rsUltimaFoto);
$fotoRequisitada = $row_rsUltimaFoto['foto_id'];
$foto = $row_rsUltimaFoto['foto_id']+1;
$insertSQL = [sprintf](http://br.php.net/sprintf)("INSERT INTO w_floricultura (foto_foto, foto_titulo, foto_valor, foto_legenda, foto_data) VALUES ('$foto', %s, %s, %s, NOW())",
GetSQLValueString($_POST['foto_titulo'], "text"),
GetSQLValueString($_POST['foto_valor'], "text"),
GetSQLValueString($_POST['foto_legenda'], "text"));
//
function reduz_imagem_jpg($img, $max_x, $max_y, $imgNome) {
//pega o tamanho da imagem ($original_x, $original_y)
list($width, $height) = [getimagesize](http://br.php.net/getimagesize)($img);
$original_x = $width;
$original_y = $height;
// se a largura for maior que altura
if($original_x > $original_y) {
$porcentagem = (100 * $max_x) / $original_x;
} else {
$porcentagem = (100 * $max_y) / $original_y;
}
$tamanho_x = $original_x * ($porcentagem / 100);
$tamanho_y = $original_y * ($porcentagem / 100);
$dimensao = $_POST["dimensao"];
if ($dimensao=='H'){
$tamanho_x= 500;
$tamanho_y= 375;
}elseif ($dimensao=='V'){
$tamanho_y= 500;
$tamanho_x= 375;}
$image_p = imagecreatetruecolor($tamanho_x, $tamanho_y);
$image = imagecreatefromjpeg($img);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $tamanho_x, $tamanho_y, $width, $height);
return imagejpeg($image_p, $imgNome, 100);
}
//
$pasta = "fotos"; //Nome da pasta para onde vão os arquivos
if (copy($fotoTmp,"$pasta/".$foto)){
echo("<font face=verdana size=1><b>Arquivo enviado com sucesso!</b></font>");
}else{
[echo](http://br.php.net/echo) ("<font face=verdana size=1><b>Erro no envio do arquivo!</b></font>");
}
[mysql_select_db](http://br.php.net/mysql_select_db)($database);
$Result1 = [mysql_query](http://br.php.net/mysql_query)($insertSQL) or [die](http://br.php.net/die)([mysql_error](http://br.php.net/mysql_error)());
}
$insertGoTo = "index.php";
if ([isset](http://br.php.net/isset)($_SERVER['QUERY_STRING'])) {
$insertGoTo .= ([strpos](http://br.php.net/strpos)($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
[header](http://br.php.net/header)([sprintf](http://br.php.net/sprintf)("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml"](http://www.w3.org/1999/xhtml)>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Postar foto</title>
</head>
<body>
<h1>Postagem de fotos</h1>
<html>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1">
<table align="center">
<tr valign="baseline">
<td width="106" align="right" nowrap>Foto:</td>
<td width="375"><input name="foto_foto" type="file" size="32" />
</tr>
<tr valign="baseline">
<td nowrap align="right">Nome:</td>
<td><input type="text" name="foto_titulo" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Valor:</td>
<td><input type="text" name="foto_valor" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">Descrição:</td>
<td><textarea name="foto_legenda" cols="50" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Dimensionar foto:</td>
<td> <input name="dimensao" type="radio" value="V" checked="CHECKED" />
Vertical
<input name="dimensao" type="radio" value="H" />
Horizontal</td></tr>
<tr valign="baseline">
<td height="27" align="right" nowrap> </td>
<td><input name="submit" type="submit" value="Postar Foto" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>
[http://forum.imasters.com.br/public/style_emoticons/](http://forum.imasters.com.br/public/style_emoticons/)default/ermm.gifDiscussão (23)
Carregando comentários...