Ver Mensaje Individual
  #15 (permalink)  
Antiguo 10/11/2008, 15:15
Avatar de srsombrero
srsombrero
 
Fecha de Ingreso: marzo-2008
Mensajes: 128
Antigüedad: 16 años, 10 meses
Puntos: 0
Respuesta: Trabajar con Header

Hola de nuevo aca te hice una pequeña clase para que puedas hacerlo.

Espero que te sirva.

Saludos


Código PHP:
<?php

Class DescargaMp3
{
    private 
$PathVirtual;
    
    function 
__construct()
    {
        
$this->PathVirtual "";
    }
    
    function 
__call($Metodo,$Parametros)
    {
        
$Args implode(", ",$Parametros);
        echo 
"El llamado a $Metodo, fallo con los parametros $Args";
    }
    
    public function 
setPathVirtual ($Path)
    {
        if (!empty(
$Path))
            
$this->PathVirtual $Path;    
        else
            echo 
"Disculpe, debe especificar una ruta para el archivo..";
    }
    
    public function 
getPathVirtual()
    {
        return (empty(
$this->PathVirtual)) ? "El path esta vacio." $this->PathVirtual;
    }
    
    public function 
Donwload ()
    {
        if(!empty(
$this->PathVirtual) && file_exists($this->PathVirtual))
        {
            
$Filename basename($this->PathVirtual);
            
$Filename substr($Filename,0,strlen($Filename)-3);
            
$Filename $Filename."mp3";
            
header("Content-type: application/octet-stream"); 
            
header("Content-Length: ".filesize($this->PathVirtual)); 
            
header("Content-Disposition: attachment; filename=\"$Filename\"\n");
            
$Fp fopen($this->PathVirtual,"r");
            
fpassthru($Fp);
        }
        else
        {
            echo 
"El archivo no existe o no se especifico un path para descarga";
        }
    }
}
$File = new DescargaMp3();
$File->setPathVirtual("Canciones/Algo.skm");
$File->Donwload();
Jajaja llegue tarde :(.