Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa noite pessoas (:
To desenvolvendo um gerenciador de downloads com modulo de pagamento, retorno automático e essas coisas... Até ai estava beleza, só que eu quis encurtar um pouco o caminho e resolvi pegar de código que eu já tinha que fazia o gerenciamento de downloads, ai era só modificar ele um pouco e já era.
Porém... Quando estava realizando alguns testes, ele começou a dar error 500 no servidor, tanto em um Windows cm iss7 e um Linux com Cpanel!
Revirei o código de ponta a ponta e não consegui achar o erro.
Alguém sabe oque pode ser?? Segue o código:
Chamando a classe download
$dl_key = $_GET['key'];
$error = $download->download( $dl_key );
if( is_string( $error ) ):
if( $error == 'Error: download is expired.' ) header( 'location: index.php?request=download&do=response&id=expired' );
if( $error == 'Error: file does not exist.' ) header( 'location: index.php?request=download&do=response&id=invalid' );
echo $error;
endif;
Classe download:
public function download( $_dl_key, $_dl_allow_resume = true, $_dl_speed = 0 )
{
if( connection_status() != 0 ) return false;
//função get_file resgata as info key no dB e verifica se é valida e retorna o nome do arquivo,
//está função está funcionando corretamente.
$dl_file = $this->get_file( $_dl_key );
if( $dl_file === false ) return( 'Error: download is expired.' );
if( !is_file( $dl_file ) ) return( 'Error: file does not exist.' );
$dl_file_size = filesize( $dl_file );
$dl_file_offset = 0;
$dl_resumed = isset( $_SERVER['HTTP_RANGE'] ) ? true : false; header( 'Cache-Control: no-cache, must-revalidate' );
header( 'Content-Transfer-Encoding: binary' );
header( 'Content-Type: application/octet-stream' );
header( 'Content-Disposition: attachment; filename="' . basename( $dl_file ) . '"' );
header( 'Accept-Ranges: bytes' );
if( $dl_resumed && $_dl_allow_resume ):
preg_match( '/bytes=(\d+)-(\d+)?/', $_SERVER['HTTP_RANGE'], $preg_match );
$dl_file_offset = intval( $preg_match[1] );
$dl_file_end = intval( $preg_match[2] );
header( 'HTTP/1.1 206 Partial Content' );
header( 'Content-Length: ' . $dl_file_end-$dl_file_offset+1 );
header( 'Content-Range: bytes ' . $dl_file_offset . '-' . $dl_file_end . '/' . $dl_file_size );
elseif( $dl_resumed && !$_dl_allow_resume ):
return( 'Error: resuming downloads is not allowed.' );
else:
header( 'Content-Range: bytes 0-' . $dl_file_size-1 . '/' . $dl_file_size );
header( 'Content-Length: ' . $dl_file_size );
endif;
ignore_user_abort( true ); $dl_file_handle = fopen( $dl_file);
fseek( $dl_file_handle, $dl_file_offset );
while( !feof( $dl_file_handle ) && ( connection_aborted() == 0 ) ):
set_time_limit( 0 ); echo fread( $dl_file_handle, 1024*$_dl_speed );
sleep( 1 );
else:
echo fread( $dl_file_handle, 1024*8 );
endif;
ob_end_flush();
ob_flush();
flush();
ob_start();
endwhile; if( feof( $dl_file_handle ) ) $this->delete_key( $_dl_key );
fclose( $dl_file_handle );
die;
}
se alguém conseguir identificar um possível erro, agradeço.
abç
Carregando comentários...