Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    [PHP] download file video

    'giorno a tutti,

    sto usando meglio tentando di usare questa funzione di andr3a ritrovata in una ricerca su questo forum...

    codice:
    <?
    function forceDownload( &$file ) {
    	/**
    	 * Function forceDownload:
    	 *	download any type of file if it exists and is readable
    	 * -------------------------------------
    	 * @author		Andrea Giammarchi
    	 * @date		24/02/2005
    	 * @compatibility	PHP >= 4.3.0
    	 */
    	if( file_exists( $file ) == true && is_readable( $file ) == true ) {
    		$filename = &basename( $file );
    		if( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
    			$parsename = &explode( '.', $filename );
    			$last = count( $parsename ) - 1;
    			$filename = &implode( '%2E', array_slice( $parsename, 0, $last ) );
    			$filename .= '.'.$parsename[$last];
    		}
    		$content = '';
    		$fo = &fopen( $file, 'rb' );
    		while( !feof( $fo ) ) {
    			$content .= fgets( $fo );
    		}
    		fclose( $fo );
    		header( 'Content-Type: application/octet-stream' );
    		header( 'Content-Disposition: attachment; filename='.$filename );
    		header( 'Content-Length:'.strlen( $content ) );
    		header( 'Content-Transfer-Encoding: binary' );
    		echo $content;
    		exit(0);
    	}
    }
    
    $myFile = $_REQUEST['myFile'];
    forceDownload( $myFile );
    
    ?>

    passo poi la chiamata in questo modo

    codice:
    Video
    il download parte sia da Firefox che da IE ma il file scaricato è di un peso minore rispetto all'originale e di conseguenza il video non vine riprodotto andando in errore.

    Sapreste darmi una mano ?

    Grazie

    SK

  2. #2
    per la cronaca, credo di aver risolto in questo modo

    codice:
    <?php
    function download ($nome, $path) {
    
    $size    = filesize ($path);
    $fp    = fopen ($path, "rb");
    $binary    = fread ($fp, $size);
    fclose ($fp);
     	    
    $nome = stripslashes ($nome);
    
    if (strpos($_SERVER['HTTP_USER_AGENT'],"Gecko")) {
    $nome = strtolower ($nome);
    $nome = str_replace("ä","a",$nome);
    $nome = str_replace("ö","o",$nome);
    }
    	
    header("Pragma: public");
    header("Cache-control: private");
    header("Expires: 0");
    header("Content-type: application/RFC822");
    header("Content-type: octet/stream\n");
    header("Content-transfer-encoding: binary\n");
    header("Content-Disposition: attachment; filename=".$nome."\n");
    header("Content-Length:".$size);
    echo $binary;
    exit();
    }	
    
    	
    download ($_REQUEST['myFile'], $_REQUEST['path']);
    ?>
    adesso faccio dei test

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.