Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - :ohk<any>

#71
Bueno es es muy simple, al momento de subirlo, me imagino que tienes una ruta a donde lo subiste, por ejemplo:

/var/www/subir_archivos/imagenes_subidas/imagen.png

Teniendo la ruta del archivo y el nombre del mismo puedes hacer la eliminación con la función que te dije.

Ahora bien si no estas guardando la ruta en alguna parte, deberías hacerlo para así poder eliminarlo.

Saludos cordiales
#72
Puedes hacerlo usando la función
Código (php) [Seleccionar]
unlink("nombre_archivo.png")

Saludos
#73
Hola foro, perdón por esta pregunta que quizás para muchos de ustedes sea un poco tonta, pero para terminar mi educación en LAMP, me falta aprender 2 tecnologías que considero son muy importantes, entre ellas Phyton y Perl.

Y quería preguntar a los expertos acá, por cual de ambas tecnologías debería empezar y cual es mejor manejar a corto plazo, porque no quiero meterme en ambas solo quisiera meterme en una de lleno hasta conocer al menos un 40%.

Espero me puedan ayudar.

Saludos Cordiales.




Bueno, leyendo temas antiguos en el mismo foro y en otros sitios web, he ido marcando uno por uno, y he llegado a la conclusión de que Python es mucho mejor que Perl, incluso Google lo usa, entonces creo que me voy a inclinar por el mismo.

Saludos cordiales.
#74
PHP / Re: Mysql, Php, pdo y goto.
1 Enero 2014, 18:35 PM
Cita de: el-brujo en 31 Diciembre 2013, 20:25 PM
estoy preparando una entrada en el blog sobre las diferencias entre mysql y mysqli (libmysql  y mysqlnd) xD

En realidad para conectar PHP con MySQL hay tres opciones, no dos.


  • ext/mysql (not recommended) (libmysql)
  • ext/mysqli (mysqlnd)
  • PDO_MySQL

Deberías usar Mysqli (mysql improved, mejorado) pero el problema es que muchos CMS aún usan mysql y muchos ejemplos de código se basan en mysql.


Yo también recomiendo el uso del MySQLi y a pesar de que muchos CMS usan el mysql, pronto se actualizaran obligados por que mysql quedo obsoleto.
#75
Cita de: Senior++ en 20 Diciembre 2013, 09:45 AM
Hace ya mucho tiempo que no lo juego, ahora juego a league of legends

+1
#76
PHP / Re: Cursos gratuitos y de pago PHP
20 Diciembre 2013, 15:39 PM
Aprende PHP a fondo y cuando lo domines toma la certificación Zend.

http://www.zend.com/services/certification/php-certification/

Saludos
#77
La mejor decisión creo yo.
#78
PHP / Re: Pequeños trucos en PHP
10 Diciembre 2013, 20:53 PM
Retorna la conversión de números a letras.

Código (php) [Seleccionar]

<?php

class EnLetras
{
  var 
$Void "";
  var 
$SP " ";
  var 
$Dot ".";
  var 
$Zero "0";
  var 
$Neg "Menos";
  
function 
ValorEnLetras($x$Moneda 
{
    
$s="";
    
$Ent="";
    
$Frc="";
    
$Signo="";
        
    if(
floatVal($x) < 0)
     
$Signo $this->Neg " ";
    else
     
$Signo "";
    
    if(
intval(number_format($x,2,'.','') )!=$x//<- averiguar si tiene decimales
      
$s number_format($x,2,'.','');
    else
      
$s number_format($x,0,'.','');
       
    
$Pto strpos($s$this->Dot);
        
    if (
$Pto === false)
    {
      
$Ent $s;
      
$Frc $this->Void;
    }
    else
    {
      
$Ent substr($s0$Pto );
      
$Frc =  substr($s$Pto+1);
    }

    if(
$Ent == $this->Zero || $Ent == $this->Void)
       
$s "Cero ";
    elseif( 
strlen($Ent) > 7)
    {
       
$s $this->SubValLetra(intvalsubstr($Ent0,  strlen($Ent) - 6))) . 
             
"Millones " $this->SubValLetra(intval(substr($Ent,-66)));
    }
    else
    {
      
$s $this->SubValLetra(intval($Ent));
    }

    if (
substr($s,-99) == "Millones " || substr($s,-77) == "Millón ")
       
$s $s "de ";

    
$s $s $Moneda;

    if(
$Frc != $this->Void)
    {
       
$s $s " Con " $this->SubValLetra(intval($Frc)) . "Centavos";
       
//$s = $s . " " . $Frc . "/100";
    
}
    
//return ($Signo . $s . " M.N.");
return ($Signo $s);
   
}


function 
SubValLetra($numero
{
    
$Ptr="";
    
$n=0;
    
$i=0;
    
$x ="";
    
$Rtn ="";
    
$Tem ="";

    
$x trim("$numero");
    
$n strlen($x);

    
$Tem $this->Void;
    
$i $n;
    
    while( 
$i 0)
    {
       
$Tem $this->Parte(intval(substr($x$n $i1). 
                           
str_repeat($this->Zero$i )));
       If( 
$Tem != "Cero" )
          
$Rtn .= $Tem $this->SP;
       
$i $i 1;
    }

    
    
//--------------------- GoSub FiltroMil ------------------------------
    
$Rtn=str_replace(" Mil Mil"" Un Mil"$Rtn );
    while(
1)
    {
       
$Ptr strpos($Rtn"Mil ");       
       If(!(
$Ptr===false))
       {
          If(! (
strpos($Rtn"Mil ",$Ptr 1) === false ))
            
$this->ReplaceStringFrom($Rtn"Mil """$Ptr);
          Else
           break;
       }
       else break;
    }

    
//--------------------- GoSub FiltroCiento ------------------------------
    
$Ptr = -1;
    do{
       
$Ptr strpos($Rtn"Cien "$Ptr+1);
       if(!(
$Ptr===false))
       {
          
$Tem substr($Rtn$Ptr ,1);
          if( 
$Tem == "M" || $Tem == $this->Void)
             ;
          else          
             
$this->ReplaceStringFrom($Rtn"Cien""Ciento"$Ptr);
       }
    }while(!(
$Ptr === false));

    
//--------------------- FiltroEspeciales ------------------------------
    
$Rtn=str_replace("Diez Un""Once"$Rtn );
    
$Rtn=str_replace("Diez Dos""Doce"$Rtn );
    
$Rtn=str_replace("Diez Tres""Trece"$Rtn );
    
$Rtn=str_replace("Diez Cuatro""Catorce"$Rtn );
    
$Rtn=str_replace("Diez Cinco""Quince"$Rtn );
    
$Rtn=str_replace("Diez Seis""Dieciseis"$Rtn );
    
$Rtn=str_replace("Diez Siete""Diecisiete"$Rtn );
    
$Rtn=str_replace("Diez Ocho""Dieciocho"$Rtn );
    
$Rtn=str_replace("Diez Nueve""Diecinueve"$Rtn );
    
$Rtn=str_replace("Veinte Un""Veintiun"$Rtn );
    
$Rtn=str_replace("Veinte Dos""Veintidos"$Rtn );
    
$Rtn=str_replace("Veinte Tres""Veintitres"$Rtn );
    
$Rtn=str_replace("Veinte Cuatro""Veinticuatro"$Rtn );
    
$Rtn=str_replace("Veinte Cinco""Veinticinco"$Rtn );
    
$Rtn=str_replace("Veinte Seis""Veintiseís"$Rtn );
    
$Rtn=str_replace("Veinte Siete""Veintisiete"$Rtn );
    
$Rtn=str_replace("Veinte Ocho""Veintiocho"$Rtn );
    
$Rtn=str_replace("Veinte Nueve""Veintinueve"$Rtn );

    
//--------------------- FiltroUn ------------------------------
    
If(substr($Rtn,0,1) == "M"$Rtn "Un " $Rtn;
    
//--------------------- Adicionar Y ------------------------------
    
for($i=65$i<=88$i++)
    {
      If(
$i != 77)
         
$Rtn=str_replace("a " Chr($i), "* y " Chr($i), $Rtn);
    }
    
$Rtn=str_replace("*""a" $Rtn);
    return(
$Rtn);
}


function 
ReplaceStringFrom(&$x$OldWrd$NewWrd$Ptr)
{
  
$x substr($x0$Ptr)  . $NewWrd substr($xstrlen($OldWrd) + $Ptr);
}


function 
Parte($x)
{
    
$Rtn='';
    
$t='';
    
$i='';
    Do
    {
      switch(
$x)
      {
         Case 
0:  $t "Cero";break;
         Case 
1:  $t "Un";break;
         Case 
2:  $t "Dos";break;
         Case 
3:  $t "Tres";break;
         Case 
4:  $t "Cuatro";break;
         Case 
5:  $t "Cinco";break;
         Case 
6:  $t "Seis";break;
         Case 
7:  $t "Siete";break;
         Case 
8:  $t "Ocho";break;
         Case 
9:  $t "Nueve";break;
         Case 
10$t "Diez";break;
         Case 
20$t "Veinte";break;
         Case 
30$t "Treinta";break;
         Case 
40$t "Cuarenta";break;
         Case 
50$t "Cincuenta";break;
         Case 
60$t "Sesenta";break;
         Case 
70$t "Setenta";break;
         Case 
80$t "Ochenta";break;
         Case 
90$t "Noventa";break;
         Case 
100$t "Cien";break;
         Case 
200$t "Doscientos";break;
         Case 
300$t "Trescientos";break;
         Case 
400$t "Cuatrocientos";break;
         Case 
500$t "Quinientos";break;
         Case 
600$t "Seiscientos";break;
         Case 
700$t "Setecientos";break;
         Case 
800$t "Ochocientos";break;
         Case 
900$t "Novecientos";break;
         Case 
1000$t "Mil";break;
         Case 
1000000$t "Millón";break;
      }

      If(
$t == $this->Void)
      {
        
$i $i 1;
        
$x $x 1000;
        If(
$x== 0$i 0;
      }
      else
         break;
           
    }while(
$i != 0);
   
    
$Rtn $t;
    Switch(
$i)
    {
       Case 
0$t $this->Void;break;
       Case 
1$t " Mil";break;
       Case 
2$t " Millones";break;
       Case 
3$t " Billones";break;
    }
    return(
$Rtn $t);
}

}
      
?>



Forma de uso:

La funcion ValorEnLetras nos exige 2 parámetros entre ellos las siglas de la moneda y el valor.

Código (php) [Seleccionar]

$num = 1200;
$valor=new EnLetras();
$literal = $valor->ValorEnLetras($num,"$USD");
echo $literal;


La función ValorEnLetras también puede enviar su segundo parámetro en blanco.

Código (php) [Seleccionar]
$literal = $valor->ValorEnLetras($num,"");

Saludos
#79
Es solo una idea posible.

Espero no suceda :P
#80
PHP / Re: Ayuda backup php mysql
10 Diciembre 2013, 17:03 PM
Asumo que necesitas un código que te ayude en esto no?

Código (php) [Seleccionar]

<?php 
class Backup{
    private 
$usuario;
    private 
$pass;
    private 
$database;
    private 
$servidor;
    private 
$nombre_archivo;
    private 
$ruta_carpeta;
    
    public function 
__construct($db 'basededatos' $directorio 'backups'$usuario 'usuario'$pass 'password'$servidor 'localhost') {
        
$this->usuario $usuario;
        
$this->pass $pass;
        
$this->database $db;
        
$this->servidor $servidor;
        
        
// configurar las rutas a las carpetas
        
$this->ruta_carpeta $this->formatearRuta($directorio);
        
    }
    
    public function 
getNombre(){
        return 
$this->nombre_archivo;
    }
    
    public function 
getRutaCarpeta(){
        return 
$this->ruta_carpeta;
    }

    public function 
generateBackupSQL($nombre$table false){
        
// escapamos espacios al nombre del backup
        
$nombre $this->limpiarNombre($nombre);
        
$this->nombre_archivo $nombre.'.sql';
        
// ver q sistema operativo tenemos
        
        
        
if (strtoupper(substr(PHP_OS03)) === 'WIN'){
            
//Si es Windows
            
$this->generateWindows($nombre$table);
        }else{
            
$this->generateLinux($nombre$table);
        }
        return 
true;
        
    }
    
    public function 
generateBackupZip($nombre$table false){
        
// escapamos espacios al nombre del backup
        
$this->generateBackupSQL($nombre$table);
        
$this->comprimirZip(substr($this->nombre_archivo,0, -4));
        
unlink($this->ruta_carpeta.$this->nombre_archivo);
        
$this->nombre_archivo substr($this->nombre_archivo,0, -4).'.zip';
        
        return 
true;        
    }
    
    
// genera el backup para Windows
    
private function generateWindows($nombre$table false){
        
// agregamos la consulta y el usuario
        
$cmd $this->ruta_carpeta."mysqldump.exe -u $this->usuario ";
        
// si existe contraseña la agregamos
        
if($this->pass != ''
            
$cmd .= "-p$this->pass ";
        
// si existe servidor distinto al local
        
if($this->servidor != 'localhost' and $this->servidor != '127.0.0.1' and $this->servidor != '')
            
$cmd .= "-h $this->servidor ";        
        
// seleccionamos la base de datos
        
$cmd .= $this->database ";
        
// si existe una tabla 
        
if($table)
            
$cmd .= $table ";
        
//definimos el nombre para el backup
        
$cmd .= " > $this->ruta_carpeta$nombre.sql ";

        
shell_exec($cmd);
    }
    
    
// genera el backup para Linux
    
private function generateLinux($nombre$table false){
        
// agregamos la consulta y el usuario
        
$cmd "mysqldump -u $this->usuario ";
        
// si existe contraseña la agregamos
        
if($this->pass != ''
            
$cmd .= "-p$this->pass ";
        
// si existe servidor distinto al local
        
if($this->servidor != 'localhost' and $this->servidor != '127.0.0.1' and $this->servidor != '')
            
$cmd .= "-h $this->servidor ";        
        
// seleccionamos la base de datos
        
$cmd .= $this->database ";
        
// si existe una tabla 
        
if($table)
            
$cmd .= $table ";
        
//definimos el nombre para el backup
        
$cmd .= " > $this->ruta_carpeta$nombre.sql ";

        
shell_exec($cmd);
    }
    
    public function 
restaurarBackup($nombre){
        
$this->nombre_archivo $nombre;
        
// verifica si el archivo esta compreso
        
switch (substr($nombre, -4)) {
        case 
'.zip':
            
$this->descomprimirZip($nombre);
            
$nombre substr($nombre0, -4).'.sql';
            break;
        case 
'.rar':
            
/// descomprimir rar
            
break;
        }
        
        
        if (
strtoupper(substr(PHP_OS03)) === 'WIN'){
            
//Si es Windows
            
$this->restaurarWindows($nombre);
        }else{
            
// si es linux u otro SO
            
$this->restaurarLinux($nombre);
        }
        return 
true;
    }
    
    private function 
restaurarWindows($nombre){

        
// establese el nombre de usuario
        
$cmd $this->ruta_carpeta."mysql.exe -u $this->usuario ";
        
// si existe contraseña la agregamos
        
if($this->pass != ''
            
$cmd .= "-p$this->pass ";
        
// si existe servidor distinto al local
        
if($this->servidor != 'localhost' and $this->servidor != '127.0.0.1' and $this->servidor != '')
            
$cmd .= "-h $this->servidor ";
        
// seleccionamos la base de datos y la ruta del archivo a restaurar
        
$cmd .= $this->database < $this->ruta_carpeta$nombre";

        
// ejecuta el comando
        
shell_exec($cmd);
        
// si el archivo q se llamo a restaurar es un archivo compreso elimina el .sql q fue descompreso
        
if(substr($this->nombre_archivo, -4) != '.sql')
            
unlink($this->ruta_carpeta.$nombre);
        
        return 
true;
    }
    
    private function 
restaurarLinux($nombre){

        
// establese el nombre de usuario
        
$cmd "mysql -u $this->usuario ";
        
// si existe contraseña la agregamos
        
if($this->pass != ''
            
$cmd .= "-p$this->pass ";
        
// si existe servidor distinto al local
        
if($this->servidor != 'localhost' and $this->servidor != '127.0.0.1' and $this->servidor != '')
            
$cmd .= "-h $this->servidor ";
        
// seleccionamos la base de datos y la ruta del archivo a restaurar
        
$cmd .= $this->database < $this->ruta_carpeta$nombre";

        
// ejecuta el comando
        
shell_exec($cmd);
        
// si el archivo q se llamo a restaurar es un archivo compreso elimina el .sql q fue descompreso
        
if(substr($this->nombre_archivo, -4) != '.sql')
            
unlink($this->ruta_carpeta.$nombre);
        
        return 
true;
    }
    
    private function 
descomprimirZip($nombre){
        
$zip = new ZipArchive();
        if(
$zip->open($this->ruta_carpeta.'/'.$nombre) === true){
            
$zip->extractTo($this->ruta_carpeta.'/');
            
$zip->close();
            return 
true;
        }
        
        return 
false;
    }

    private function 
comprimirZip($nombre){
        
$zip = new ZipArchive();
        
$filename $this->ruta_carpeta.'/'.$nombre.'.zip';
        
        if(
$zip->open($filenameZipArchive::CREATE) === true){
            
$zip->addFile($this->ruta_carpeta."/".$nombre.'.sql'$nombre.'.sql' );
            
$zip->close();
            return 
true;
        }else{
            return 
false;
        }
    }
    
    public function 
limpiarNombre($nombre){
        
$nombre trim($nombre);
        return 
preg_replace("/[^a-z0-9]+/i""-"$nombre);
    }
    
    private function 
formatearRuta($ruta){
        
/**
         * Reemplaza los separadores de directorio incorrectos por los correctos segun el sistema operativo
         * por lo que es lo mismo poner:
         * 
         * carpeta1/carpeta2/carpeta3
         * o
         * carpeta1\carpeta2\carpeta3
         * o
         * carpeta1/carpeta2\carpeta3
         */
        

        
$ruta trim($ruta'\\/');
        
$ruta str_replace('\\',DIRECTORY_SEPARATOR$ruta);
        
$ruta str_replace('/',DIRECTORY_SEPARATOR$ruta).DIRECTORY_SEPARATOR;
        
//return getcwd().DIRECTORY_SEPARATOR.$ruta;  //retorna ruta absoluta
        
return $ruta;
    }
}

?>



En tu carpeta de Buckups deberías tener el mysqldump.exe.

Saludos