NO HACE BIEN EL UPLOAD DE IMAGEN
Publicado por Luthien (2 intervenciones) el 24/10/2006 17:47:07
Hola buenas tardes,
Soy novata en esto del php, y he preparado una pagina donde se inserta un texto y una imagen a una base de datos, despues sube la imagen...
Inserta bien los datos en la base de datos, pero el upload no lo hace bien...
Dejo el codigo aki por si alguien puede ayudarme..
Un abrazo...
<?php require_once("accesso.php") ?>
<?php
include_once('clases/clsCampanyes.cls');
if(isset($_REQUEST["texto"])&&isset($_REQUEST["Crear"]))
{
$categorias=new clsNoticia;
$max=$categorias->crea();
$origen=$HTTP_POST_FILES['archivo']['name'];
$tmp_origen=$HTTP_POST_FILES['archivo']['tmp_name'];
$tipo_imagen=$HTTP_POST_FILES['archivo']['type'];
$destino='img/';
$resx=200;
$resy=200;
$id=$max;
if((is_uploaded_file($tmp_origen)) && (strpos($tipo_imagen, "jpeg")))//si se upload bien y es .jpg
{
$nombre_archivo="noticia".$id.".jpg";
$nombre_archivot=$destino."tbcampanya".$id.".jpg";
@move_uploaded_file($tmp_origen,$destino."/".$nombre_archivo);
$image_path=$destino."/".$nombre_archivo;
$img = null;
$ext = strtolower(end(explode('.', $image_path)));
if ($ext == 'jpg' || $ext == 'jpeg')
{
$img = @ImageCreateFromJPEG($image_path);
}
if ($img)
{
# Get image size and scale ratio
$width = imagesx($img);
$height = imagesy($img);
$scale = min($resx/$width, $resy/$height);
if ($scale < 1)
{
$new_width = floor($scale*$width);
$new_height = floor($scale*$height);
}
else
{
$scale=1;
$new_width = floor($scale*$width);
$new_height = floor($scale*$height);
}
$tmp_img = ImageCreateTrueColor($new_width, $new_height);
ImageCopyResized($tmp_img, $img, 0, 0, 0, 0,$new_width, $new_height, $width, $height);
ImageJPEG($tmp_img,$nombre_archivot,100);
}
$valores=array("texto"=>addslashes($_REQUEST["texto"]),"foto"=>$nombre_archivot);
}
else
{
$valores=array("texto"=>addslashes($_REQUEST["texto"]),"foto"=>$_REQUEST["archivo"]);
}
$categorias->actualizar($max,$valores);
echo"<script>window.location='campanyes.php'</script>";
}
elseif(isset($_REQUEST["Cancelar"])) echo"<script>window.location='campanyes.php'</script>";
?>
<html><head><title>--------------------------------------</title>
<script language="JavaScript" type="text/javascript" src="funciones.js"></script>
<LINK REL="stylesheet" HREF="estilo/estilo.css" TYPE="TEXT/CSS">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script languaje="javascript">
function ponimagen(origen,destino)
{
fichero=replace(origen.value,'\\','/');
fichero=replace(fichero,' ','%20');
alert("file///"+fichero);
document.getElementById(destino).src=origen.value;
}
</script>
</head>
<body leftmargin="0" topmargin="0">
<table align="center" border="0" cellpadding="0" cellspacing="0" width="789">
<tr>
<td colspan="3"><img src="imagenes/index_07.gif" alt="" height="98" width="177" vspace="10"></td>
</tr>
<tr>
<td width="177"><img src="../Images/campanyeslogo.jpg" width="177" height="27" border="0" alt=""></td>
<td width="3"><img src="imagenes/pixel.gif" width="3" height="1" border="0" alt=""></td>
<td bgcolor="#53BD48" class="txtNormal_blanco" width="609"> <a href="menu.php" class="link_3">Inici</a> > <a href="campanyes.php" class="link_3">Gestió de les Campanyes </a> > <strong>Crear</strong></td>
</tr>
<tr>
<td colspan="3"><img src="imagenes/pixel.gif" width="1" height="5" border="0" alt=""></td>
</tr>
<tr>
<td valign="top" colspan="3">
<form name="frmSocios" action="crearcampanya.php" method="post" enctype="multipart/form-data">
<table cellspacing="2" cellpadding="4" style="border:1px solid #53BD48;" width="100%">
<tr>
<td valign="top" class="txtNormal_negro">Campanyes: <br>
<textarea class="txtNormal_negro" name="texto" cols="70" rows="6"></textarea></td>
<td valign="top" class="txtNormal_negro">Imatge:<br> <input class="txtNormal_negro" name="archivo" type="file"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Crear" name="Crear">
<input type="submit" value="Cancel·lar" name="Cancelar">
</td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td colspan="3" height="10"><img src="imagenes/pixel.gif" width="1" height="10" border="0" alt=""></td>
</tr>
<tr>
<td colspan="3" bgcolor="#53BD48" height="10"><img src="imagenes/pixel.gif" width="1" height="10" border="0" alt=""></td>
</tr>
</table>
</body></html>
Soy novata en esto del php, y he preparado una pagina donde se inserta un texto y una imagen a una base de datos, despues sube la imagen...
Inserta bien los datos en la base de datos, pero el upload no lo hace bien...
Dejo el codigo aki por si alguien puede ayudarme..
Un abrazo...
<?php require_once("accesso.php") ?>
<?php
include_once('clases/clsCampanyes.cls');
if(isset($_REQUEST["texto"])&&isset($_REQUEST["Crear"]))
{
$categorias=new clsNoticia;
$max=$categorias->crea();
$origen=$HTTP_POST_FILES['archivo']['name'];
$tmp_origen=$HTTP_POST_FILES['archivo']['tmp_name'];
$tipo_imagen=$HTTP_POST_FILES['archivo']['type'];
$destino='img/';
$resx=200;
$resy=200;
$id=$max;
if((is_uploaded_file($tmp_origen)) && (strpos($tipo_imagen, "jpeg")))//si se upload bien y es .jpg
{
$nombre_archivo="noticia".$id.".jpg";
$nombre_archivot=$destino."tbcampanya".$id.".jpg";
@move_uploaded_file($tmp_origen,$destino."/".$nombre_archivo);
$image_path=$destino."/".$nombre_archivo;
$img = null;
$ext = strtolower(end(explode('.', $image_path)));
if ($ext == 'jpg' || $ext == 'jpeg')
{
$img = @ImageCreateFromJPEG($image_path);
}
if ($img)
{
# Get image size and scale ratio
$width = imagesx($img);
$height = imagesy($img);
$scale = min($resx/$width, $resy/$height);
if ($scale < 1)
{
$new_width = floor($scale*$width);
$new_height = floor($scale*$height);
}
else
{
$scale=1;
$new_width = floor($scale*$width);
$new_height = floor($scale*$height);
}
$tmp_img = ImageCreateTrueColor($new_width, $new_height);
ImageCopyResized($tmp_img, $img, 0, 0, 0, 0,$new_width, $new_height, $width, $height);
ImageJPEG($tmp_img,$nombre_archivot,100);
}
$valores=array("texto"=>addslashes($_REQUEST["texto"]),"foto"=>$nombre_archivot);
}
else
{
$valores=array("texto"=>addslashes($_REQUEST["texto"]),"foto"=>$_REQUEST["archivo"]);
}
$categorias->actualizar($max,$valores);
echo"<script>window.location='campanyes.php'</script>";
}
elseif(isset($_REQUEST["Cancelar"])) echo"<script>window.location='campanyes.php'</script>";
?>
<html><head><title>--------------------------------------</title>
<script language="JavaScript" type="text/javascript" src="funciones.js"></script>
<LINK REL="stylesheet" HREF="estilo/estilo.css" TYPE="TEXT/CSS">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script languaje="javascript">
function ponimagen(origen,destino)
{
fichero=replace(origen.value,'\\','/');
fichero=replace(fichero,' ','%20');
alert("file///"+fichero);
document.getElementById(destino).src=origen.value;
}
</script>
</head>
<body leftmargin="0" topmargin="0">
<table align="center" border="0" cellpadding="0" cellspacing="0" width="789">
<tr>
<td colspan="3"><img src="imagenes/index_07.gif" alt="" height="98" width="177" vspace="10"></td>
</tr>
<tr>
<td width="177"><img src="../Images/campanyeslogo.jpg" width="177" height="27" border="0" alt=""></td>
<td width="3"><img src="imagenes/pixel.gif" width="3" height="1" border="0" alt=""></td>
<td bgcolor="#53BD48" class="txtNormal_blanco" width="609"> <a href="menu.php" class="link_3">Inici</a> > <a href="campanyes.php" class="link_3">Gestió de les Campanyes </a> > <strong>Crear</strong></td>
</tr>
<tr>
<td colspan="3"><img src="imagenes/pixel.gif" width="1" height="5" border="0" alt=""></td>
</tr>
<tr>
<td valign="top" colspan="3">
<form name="frmSocios" action="crearcampanya.php" method="post" enctype="multipart/form-data">
<table cellspacing="2" cellpadding="4" style="border:1px solid #53BD48;" width="100%">
<tr>
<td valign="top" class="txtNormal_negro">Campanyes: <br>
<textarea class="txtNormal_negro" name="texto" cols="70" rows="6"></textarea></td>
<td valign="top" class="txtNormal_negro">Imatge:<br> <input class="txtNormal_negro" name="archivo" type="file"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Crear" name="Crear">
<input type="submit" value="Cancel·lar" name="Cancelar">
</td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td colspan="3" height="10"><img src="imagenes/pixel.gif" width="1" height="10" border="0" alt=""></td>
</tr>
<tr>
<td colspan="3" bgcolor="#53BD48" height="10"><img src="imagenes/pixel.gif" width="1" height="10" border="0" alt=""></td>
</tr>
</table>
</body></html>
Valora esta pregunta
0