Viewing file: ftpuploadng.php (7.22 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();
$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'];
$fichero=str_replace(" ","_",$_FILES['upload']['name']); $fichero=elimina_acentos($fichero); $imagen_bruta=elimina_acentos(TRIM(ucwords(strtolower($_POST['apellidos'])))). ",". elimina_acentos(strtoupper($_POST['titulo'])); $Arrayextension_imagen=explode(".",$_FILES['imagen']['name']);
$extensionimagen=$Arrayextension_imagen[count($Arrayextension_imagen)-1]; $imagen=str_replace(" ","_",$imagen_bruta.".".$extensionimagen);
// a ver la �apa: ver donde esta el titulo-nombre. voy a hacer el nombre componiendolo yo, con independencia del original $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']; $fecha_hora=STRVAL(INTVAL((date("H"))+DIF_HORARIA)); IF (STRLEN($fecha_hora)==1){$fecha_hora='0'.$fecha_hora;} $fecha=date("Y-m-d")." ".$fecha_hora.date(":i:s"); ; $tamano=intval(filesize($localfile)/1000); $fichero=str_replace(" ","_", elimina_acentos(TRIM(ucwords(strtolower($_POST['apellidos'])))).",". elimina_acentos(TRIM(ucwords(strtolower($_POST['nombre']))))."-". elimina_acentos(strtoupper($_POST['titulo']))). elimina_acentos("-({$genero}"). ",". elimina_acentos("$subgenero)"). ".zip"; echo $fichero;
$ruta="http://www.cocido-maragato.com/extras/fb2/".$fichero; mysql_close($conn);
if (isset($_POST['submit'])) {
$ftp_server = "62.193.202.9"; // add server name $ftp_user_name = "gp571133"; // add user name $ftp_user_pass = "j41ondtj"; // add password $dst_dir = "web/extras/fb2/"; // add destination directory ( www/upload/ )
//class constructor $ftp = new ftp($ftp_server,$ftp_user_name,$ftp_user_pass,$dst_dir);
// sending any file // FTP_ASCII or FTP_BINARY $resultado = $ftp->sendfile($fichero, $localfile, "FTP_BINARY");
if ($resultado) {
echo $error = '<h1>Fichero subido correctamente.'.$fichero."</h1>";
$conn=mysql_connect("localhost","placasci","ilvm1rg1"); mysql_select_db("placasci_papyre",$conn)or die(mysql_error()); $sql="insert into libros (autor,titulo,correo,genero,subgenero,fecha_subida,ruta,tamano,anyo) values('$autor','$titulo','$correo','$genero','$subgenero','$fecha','$ruta',$tamano,'$anyo')"; 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;
$localfile = $_FILES['imagen']['tmp_name']; if (strlen(trim($extensionimagen))==0){ $negativo=1; }else{ copy ($localfile,"./includes/$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); $sinopsis=$_POST['sinopsis']; if (strlen(trim($sinopsis))==0){ $negativo=1; } if ($negativo==0){ $querysip="insert into sinopsis (imagename, id_book, sinopsis) values ('$imagen','{$rowid['id']}','{$sinopsis}')";
mysql_query($querysip,$conn); $querysip="update libros set sinopsis='*' where id={$rowid['id']}";
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 }
echo "<SCRIPT>ap_showWaitMessage('waitDiv', 0);</SCRIPT>";
?> </body> </html>
|