Viewing file: ftpupload3.php (8.58 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<html> <head> <link rel="stylesheet" type="text/css" href="nuevo.css">
<link rel="STYLESHEET" type="text/css" href="estilo.css">
<? require "./class.ftp.php"; include "conn.php"; $debug=0; if ($debug==1){ echo "<pre>"; print_r($_REQUEST); PRINT_R($_FILES); }
echo "
<div ID='waitDiv' style='position:absolute;left:300;top:300;visibility:hidden'> <table cellpadding='6' cellspacing='0' border='1' bgcolor='#000000' bordercolor='#FFFFFF'> <tr><td align=center> <font color='#ffffff' face='Verdana' size='4'>Subiendo libro.....</font> <img src='cargando.gif' border='1'> </td> </tr></table> </div>
<SCRIPT> <!-- var DHTML = (document.getElementById || document.all || document.layers); function ap_getObj(name) { if (document.getElementById) { return document.getElementById(name).style; } else if (document.all) { return document.all[name].style; } else if (document.layers) { return document.layers[name]; } } function ap_showWaitMessage(div,flag) { if (!DHTML) return; var x = ap_getObj(div); x.visibility = (flag) ? 'visible':'hidden' if(! document.getElementById) if(document.layers) x.left=280/2; return true; } ap_showWaitMessage('waitDiv', 3); //--> </SCRIPT>
<SCRIPT> ap_showWaitMessage('waitDiv', 2); </SCRIPT> </head> <body>"; flush();
$date = new DateTime(date("Y-m-d H:i:s")); $date->modify("+".DIF_HORARIA." hour"); $fecha=$date->format("Y-m-d H:i:s");
//$fecha=date("Y-m-d")." ".(date("H")+7).date(":i:s"); echo strlen(trim($_REQUEST['localidadList']));
if (empty ($_POST['nombre']) or empty ($_POST['apellidos']) or empty ($_POST['titulo']) or empty ($_FILES['upload']['name']) or empty ($_POST['provinciaList']) or (strlen(trim($_REQUEST['localidadList']))==26)){ echo "<center><h1>campos obligatorios: <b>autor(nombre y apellidos), titulo, fichero, genero, subgenero</b></h1>"; ?><center><a href='javascript:history.back()' style="text-decoration:none"><img src=volver.png border=0></img></a> <?php die(); }
if (!strpos($_FILES['upload']['name'],".zip") and !strpos($_FILES['upload']['name'],".ZIP")){ echo "<h1>solo se admiten ficheros en formato ZIP</h1>"; die(); }
$queryx="select genero, subgenero from tipo where id_ajax='{$_REQUEST['provinciaList']}' and subgenero='{$_REQUEST['localidadList']}' limit 1";
flush(); $gen=mysql_fetch_array($resx=mysql_query($queryx,$conn));
echo mysql_error(); if (debug){ echo $queryx."<br>"; print_r($gen); }
$localfile = $_FILES['upload']['tmp_name'];
// nueva forma de nombrar
$sqlid="select max(id) as id from libros"; $rowid=mysql_fetch_array(mysql_query($sqlid,$conn)); unset($ultimoid); $ultimoid=$rowid['id']+1;
$Arrayextension_imagen=explode(".",$_FILES['imagen']['name']);
$extensionimagen=$Arrayextension_imagen[count($Arrayextension_imagen)-1]; $imagen=$ultimoid.".".$extensionimagen;
$autor= ucwords(strtolower($_POST['apellidos'])).", ".ucwords(strtolower($_POST['nombre'])); $titulo=ucwords(strtolower($_POST['titulo'])); $correo=$_POST['correo']; $genero=$gen['genero']; $subgenero=$gen['subgenero']; $anyo=$_POST['anyo']; $tamano=intval(filesize($localfile)/1000); $fichero=$ultimoid."-".rand(111,999).".zip"; echo $fichero;
$ruta=RUTA_FTP.$fichero; mysql_close($conn);
if (isset($_POST['submit'])) {
copy ($localfile,"../libros/$fichero");
if (copy ($localfile,"../libros/$fichero")) {
echo $error = '<h1>Fichero subido correctamente.'.$fichero."</h1>";
$conn=mysql_connect("localhost",$bbdduser,$bbddpassword); mysql_select_db($bbdd,$conn)or die(mysql_error()); $sql="insert into libros (id,autor,titulo,correo,genero,subgenero,fecha_subida,ruta,tamano,anyo,inftp) values($ultimoid, '$autor','$titulo','$correo','$genero','$subgenero','$fecha','$ruta',$tamano,'$anyo',1)"; mysql_query($sql,$conn); if(mysql_error()){ //echo $query."<br>"; echo mysql_error(); echo "<h1>error</h1>"; die(); } // ahora, sacamos el ID, para que los demas puedan "linkarlo" $query="Select max(id) as id from libros" ; $resid=mysql_query($query,$conn); echo mysql_error(); while($rowid=mysql_fetch_array($resid)){ // ahora, toca la imagen y la sinopsis $negativo=0; unset ($localfile); $localfile = $_FILES['imagen']['tmp_name']; if (strlen(trim($extensionimagen))==0){ $negativo=1; }else{ $ok=copy ($localfile,"./includes2/$imagen");
// esto es reescalado de imagen $origen="./includes2/"; $destino='./includes/'; $resize=1; $calidad=70;
imgress($origen,$destino,$resize,$calidad);
// y borramos el origen..... unlink("./includes2/$imagen"); } //primero, tenemos que sacar el id $query="select * from libros where titulo='$titulo' and autor='$autor'"; $res=mysql_query($query,$conn); $rowid=mysql_fetch_array($res); unset($sinopsis); $sinopsis=$_POST['sinopsis']; if (strlen(trim($sinopsis))==0){ $negativo=1; } if ($negativo==0){ $querysip="insert into sinopsis (imagename, id_book, sinopsis) values ('$imagen','$ultimoid','{$sinopsis}')";
mysql_query($querysip,$conn); $querysip="update libros set sinopsis='*' where id=$ultimoid";
mysql_query($querysip,$conn); ECHO mysql_error(); } }
// echo "<h3>puede enlazar directamente este libro desde su web, <b>http://placasci.exofire.net/frames/buskador.php?id=".$rowid[0]."</b>"; } else {
echo "<h2>Error al subir el fichero.({$error})</h2>"; echo $error; } }
echo '<center><a href ="entradilla.php"><img src="papyreicon.gif" WIDTH=32 HEIGHT=32></img><B>P�gina Principal</B></a>';
mysql_close($conn);
/* function elimina_acentos($cadena){ $tofind = "&:�������������������������������������������������������+[]?�!�,;�'".'\\'; $replac = "y_nnAAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn___----_-i-"."-"; return(strtr($cadena,$tofind,$replac)); } */ function ConectarFTP(){ //Permite conectarse al Servidor FTP $id_ftp=ftp_connect(SERVER,PORT); //Obtiene un manejador del Servidor FTP ftp_login($id_ftp,USER,PASSWORD); //Se loguea al Servidor FTP ftp_pasv($id_ftp,MODO); //Establece el modo de conexi�n return $id_ftp; //Devuelve el manejador a la funci�n }
function SubirArchivo($archivo_local,$archivo_remoto){ //Sube archivo de la maquina Cliente al Servidor (Comando PUT) $id_ftp=ConectarFTP(); //Obtiene un manejador y se conecta al Servidor FTP ftp_put($id_ftp,$archivo_remoto,$archivo_local,FTP_BINARY); //Sube un archivo al Servidor FTP en modo Binario ftp_quit($id_ftp); //Cierra la conexion FTP } function imgress($diror,$dirdest,$val,$qual){ $q=$qual; //open the directory if (is_dir($diror)) { if ($dh = opendir($diror)) { while (($file = readdir($dh)) !== false) { if($file == "." || $file == ".."){continue;} $k=explode(".",$file); if(strpos($k[1],"jpg")===0 || strpos($k[1],"jpeg")===0){ $salva=$dirdest.$file; $image=$diror.$file; $im =imagecreatefromjpeg("$image"); $x=imagesx($im); $y=imagesy($im); if ($x<>132 or $y<>216){ $k=array("salidaenfalso","salidaenfalso"); } $thumbnail=imagecreatetruecolor(132,216); $im_ridimensionata=imagecopyresized( $thumbnail, $im, 0, 0, 0, 0, 132, 216, $x, $y); imagejpeg($thumbnail, $salva, $q); } elseif(strpos($k[1],"gif")===0){ $salva=$dirdest.$file; $image=$diror.$file; $im =imagecreatefromgif("$image"); $x=imagesx($im); $y=imagesy($im); $thumbnail=imagecreatetruecolor(132,216); $im_ridimensionata=imagecopyresized( $thumbnail, $im, 0, 0, 0, 0, 132, 216, $x, $y); imagegif($thumbnail, $salva, $q); } elseif(strpos($k[1],"png")===0){ $salva=$dirdest.$file; $image=$diror.$file; $im =imagecreatefrompng("$image"); $x=imagesx($im); $y=imagesy($im); $thumbnail=imagecreatetruecolor(132,216); $im_ridimensionata=imagecopyresized( $thumbnail, $im, 0, 0, 0, 0, 132, 216, $x, $y); imagepng($thumbnail, $salva, $q); } else{ echo "$diror File not compatible(no jpg,gif or png)"; } flush(); } closedir($dh); }else{ echo "no se pudo abrir"; } } }
echo "<SCRIPT>ap_showWaitMessage('waitDiv', 0);</SCRIPT>";
?> </body> </html>
|