haber si alguien consigue ayudarme, con esta funcion subo las fotos a mi pagina
Código PHP:
<?
ob_start();
include('config.php'); //incluimos el config.php que contiene los datos de la conexión a la db y la sesión
if($_SESSION[level] < 1)
{
Header("Location: home.php");
}
$max=100000;
$xmax=100;
$ymax=100;
$nuevoDirectorio="fotos/";
function thumbnail($file,$dir,$ancho1,$alto1)
{
if(!file_exists($dir.$file))
{
return false;
}
if(!is_dir($dir))
{
return false;
}
$a = getimagesize($dir.$file);
$ancho=$a['0'];
$alto=$a['1'];
$comprime=false;
if ($ancho>$ancho1 || $alto>$alto1)
{
$comprime=true;
}
if ( $a['0'] > $ancho1 && $a['1'] < $alto1 )
{
$alto = ( $ancho1 * $a['1'] ) / $a['0'];
$ancho= $ancho1;
}
else if ($a['0'] < $ancho1 && $a['1'] > $alto1 )
{
$ancho = ( $alto1 * ($a['0']) ) / $a['1'];
$alto = $alto1;
}
else if ( $a['0'] > $ancho1 && $a['1'] > $alto1 )
{
if ($a['0']/$a['1']>=1)
{
$alto = ( $ancho1 * $a['1'] ) / $a['0'];
$ancho= $ancho1;
}
else
{
$ancho = ( $alto1 * ($a['0']) ) / $a['1'];
$alto = $alto1;
}
}
else
{
$ancho=$a['0'];
$alto=$a['1'];
}
$final = (int) strlen($file) - 4;
$nombre =(substr($file,0,$final));
$ext = (substr($file,-4,4));
$nombre = $nombre.$ext;
$mini = $dir."mini_".$nombre;
$alto=ceil($alto)+1;
$ancho=ceil($ancho)+1;
if ($comprime)
{
if($ext==".jpg" || $ext==".jpeg"){
$origen = imageCreateFromJPEG($dir.$file);
$imgAncho= imageSx($origen);
$imgAlto = imageSy($origen);
$imagen = imageCreatetruecolor($ancho,$alto);
ImageCopyResized($imagen,$origen,0,0,0,0,$ancho,$alto,$imgAncho,$imgAlto);
imageJPEG($imagen,$mini);
}else if($ext==".png"){
$origen = imageCreateFromPNG($dir.$file);
$imgAncho= imageSx($origen);
$imgAlto = imageSy($origen);
$imagen = imageCreatetruecolor($ancho,$alto);
ImageCopyResized($imagen,$origen,0,0,0,0,$ancho,$alto,$imgAncho,$imgAlto);
imagePNG($imagen,$mini);
}else if($ext==".gif"){
$origen = imageCreateFromGIF($dir.$file);
$imgAncho= imageSx($origen);
$imgAlto = imageSy($origen);
$imagen = imageCreatetruecolor($ancho,$alto);
ImageCopyResized($imagen,$origen,0,0,0,0,$ancho,$alto,$imgAncho,$imgAlto);
imagePNG($imagen,$mini);
}
}
return true;
}
if($enviar)
{
$file=$fichero_name;
$ext = (substr($file,-4,4));
if (($fichero_size < $max) && (($fichero_type=="image/gif") || ($fichero_type=="image/jpeg") || ($fichero_type=="image/pjpeg") || ($fichero_type=="image/x-png")))
{
move_uploaded_file($fichero , $nuevoDirectorio . $_SESSION[usuario].$ext);
print"Tu foto se envio correctamente";
$a = getimagesize( $nuevoDirectorio . $_SESSION[usuario].$ext);
if ( ( $a['0']>100 ) || ( $a['1']>100 ) )
{
thumbnail($_SESSION[usuario].$ext,$nuevoDirectorio,$xmax,$ymax);
}
}
else
{
print"El fichero ha de ser menor a $max bytes y ser de los tipos permitidos";
}
}
else { ?>
<style type="text/css">
<!--
* {FONT-FAMILY: 'Trebuchet MS' sans-serif; font-size: 9pt;}
body {
overflow-x:hidden;
overflow-y:hidden;
margin: 0;
padding: 0;
text-align: center;
}
.enviafoto {
display: block;
width: 485px;
background-image: url(fondo2.gif);
height: 25px;
border: 1px solid #999999;
text-align: center;
font-weight: bold;
color: #000000;
}
.tbformdata {
display: block;
width: 485px;
background-color: #eaeaea;
border-top: 1px dashed #487baf;
padding-top: 5px;
border-bottom: 1px dashed #487baf;
margin-bottom: 5px;
text-align: center;
}
.infoenvio {
display: block;
width: 480px;
padding: 5px;
text-align: justify;
}
-->
</style>
<script language="javascript">
function centrar() {
iz=(screen.width-document.body.clientWidth) / 2;
de=(screen.height-document.body.clientHeight) / 2;
moveTo(iz,de);
}
</script>
<title>:: Enviar Foto ::</title>
<body Scroll="NO" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" onunload="opener.location.reload()" onLoad="centrar()">
<div class="enviafoto">Buscar imagen a enviar</div>
<div class="infoenvio">"La imagen a enviar no debe exceder los 100 KB de peso.
Los formatos permitidos son: <strong>jpg y png,</strong> ambos formatos en minúsculas".</div><br>
<div class="tbformdata" border="0">
<form method="post" action="<?=$PHP_SELF?>" enctype="multipart/form-data">
<strong>Imagen:</strong>
<input type="file" name="fichero"> <input type="submit" name="enviar" value="Enviar">
</form></div></body>
<? }
ob_end_flush();
?>
ahora me lio a no saber donde meter la funcion chmod() de php, para cambiar los permisos de las fotos ke se han subido a 666, ojala alguien me pueda ayudar
saludos