¿Cómo consigo subir imágenes mediante ftp con código php?

¿Hola qué tal? Mira tengo un formulario echo con input file en el cual tengo que hacer que al pinchar en examinar suba una imagen mediante ftp pero echo con código php el problema es que no m sube nada y adema m pone que la imagen tiene que ser jpg o jpeg y todas la imágenes que subo son jpg haber si m puedes ayudar gracias de antemano
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<div>          
        <form method="POST" enctype="multipart/form-data" action="anadirimagen.php" >
<table width="100%">
<centre> SUBIR IMAGENES </centre>
<tr>
<td align="right">imagen: </td>
<td><input type="file" name="image" id="image" maxlength="45"> </td>
</tr>
<tr>
<td height="10" colspan="2" align="center">
                    <center><input type="submit" name="enviar" value="enviar"/></center>
                </td>
</tr>
</table>
</form>
        </div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<?php
    //CONEXION AL SERVIDOR FTP
require_once("function/subir_archivos.php");
       $servidor="0.0.0.0";
        $puerto="21";
        $user="servidor";
        $pass="ddd";
        $ruta="/imagenes_dddd/";
      $archivo = $_FILES['image']['imagen'];
        $subir=SubirFTP($servidor,$puerto,$user,$pass,$archivo,$ruta);
        ?>
           </div>
</body>
</html>
<?php
function SubirFTP($servidor,$puerto,$user,$pass,$archivo,$ruta)
{        
    $id_ftp=ConectarFTP($servidor,$puerto,$user,$pass);
    $archivo_local=$archivo["tmp_name"];
    $fichero=$archivo["name"];
    if(ComprobarExtension($fichero)==true)
    {
        if(ComprobarExistente($id_ftp,$ruta,$fichero)==true)
        {
            $correcto=SubirArchivo($fichero,$archivo_local,$ruta,$id_ftp);
            ftp_close($id_ftp);
            return $correcto;
        }
        else
        {
            return false;
        }    
    }
    else
    {
        return false;
    }
}
function ConectarFTP($servidor,$puerto,$user,$pass)
{  
    //Permite conectarse al Servidor FTP
    $id_ftp=ftp_connect($servidor,$puerto); //Obtiene un manejador del Servidor FTP
    if(!$id_ftp)
    {
        echo "Error al conectar.";
    }
    $login=ftp_login($id_ftp,$user,$pass); //Se loguea al Servidor FTP
    if(!$login)
    {
        echo "Error al loguearse";
    }
    ftp_pasv($id_ftp,"true"); //Establece el modo de conexion
    return $id_ftp; //Devuelve el manejador a ladie(); funcion
}
function ComprobarExtension($fichero)
{ echo($fichero);
    if(!eregi("jpeg",$fichero) && !eregi("jpg",$fichero))
    {
        ?>
<script language="JavaScript" type="text/javascript">
                alert("Las extensiones de las imagenes deben de ser jpg o jpeg.");
            </script>
<?php
        return false;
    }
    else
    {
        return true;
    }
}
function SubirArchivo($nombre_remoto,$archivo_local,$ruta,$id_ftp)
{
    echo($archivo_local);
    ftp_chdir($id_ftp,$ruta);
    $accion=ftp_put($id_ftp,$nombre_remoto,$archivo_local,FTP_ASCII);
    if($accion==true)
    {
        return true;
    }
    else
    {
        ?>
<script language="JavaScript" type="text/javascript">
                alert("No se pudo subir alguno de los ficheros. Si el problema persiste consulte con el administrator.");
            </script>
<?php
        return false;
    }
}
function ComprobarExistente($id_ftp,$ruta,$fichero)
{
    $archivos=ftp_nlist($id_ftp,$ruta);
    foreach($archivos as $indice =>$archivo)
    {
      ...

1 Respuesta

Respuesta
1
Pues mira... así como tener una idea de hacer algo en php.. pues no, pero estuve revisando algunas páginas, te pego los links, espero que de alguna forma te ayuden:
http://www.webtaller.com/construccion/lenguajes/php/lecciones/subir-archivos-php.php
http://www.webtaller.com/construccion/lenguajes/php/lessons/subir_archivos.php
http://www.desarrolloweb.com/articulos/1307.php
http://www.cristalab.com/tutoriales/subir-archivos-con-php-por-ftp-c112l/
http://www.php.net/        --esta ultima es la pagina oficial de php

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas