<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div>Hola gente:<br></div><br>en un sistema genero un archivo al que el usuario debe poder bajar a su compu ("datos.csv")<br></div>Para esto utilizo un script que baje de <br><a href="http://www.media-division.com/php-download-script-with-resume-option">http://www.media-division.com/php-download-script-with-resume-option</a><br></div>Esta muy piola: pego el contenido debajo del mensaje <br></div>El script se llama "bajar.php" y lo llamo con<br><a href="bajar.php?file=bajar/datos.csv" class = "boton2">Bajar el archivo</a><br><br></div>El problema es que funciona perfecto en mi compu y en un sitio, pero en otro, en lugar de inciar la descarga al tocar el link pone la pantalla en blanco y ahi queda.<br></div>Hoy estuve nuevamente mirando el codigo y no me doy cuenta donde esta el problema.<br></div>Lo gracioso es que para seguir adelante en mi página le puse directamente un link al archivo y al tocarlo el navegador inicia la descarga...<br></div>Como sea, si a algún Leo se le ocurre que cambiar se agradece el comentario<br></div>Gracias<br></div>Mario<br><br></div>(bajar.php)<br><div>------------------------------------------------------------------------------------------<br>/**<br> * Copyright 2012 Armand Niculescu - <a href="http://media-division.com">media-division.com</a><br> * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:<br> * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.<br> * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.<br> * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<br> */<br>// get the file request, throw error if nothing supplied<br> <br>// hide notices<br>@ini_set('error_reporting', E_ALL);<br> <br>//- turn off compression on the server<br>@apache_setenv('no-gzip', 1);<br>@ini_set('zlib.output_compression', 'Off');<br><br>if(!isset($_REQUEST['file']) || empty($_REQUEST['file'])) <br>{<br>    header("HTTP/1.0 400 Bad Request");<br>    exit;<br>}<br><br>// sanitize the file request, keep just the name and extension<br>// also, replaces the file location with a preset one ('./myfiles/' in this example)<br>$file_path  = $_REQUEST['file'];<br>$path_parts = pathinfo($file_path);<br>$file_name  = $path_parts['basename'];<br>$file_ext   = $path_parts['extension'];<br>$file_path  = './bajar/' . $file_name;<br> <br> <br>// allow a file to be streamed instead of sent as an attachment<br>$is_attachment = isset($_REQUEST['stream']) ? false : true;<br> <br>// make sure the file exists<br>if (is_file($file_path))<br>{<br>    $file_size  = filesize($file_path);<br>    $file = @fopen($file_path,"rb");<br>    if ($file)<br>    {<br>        // set the headers, prevent caching<br>        header("Pragma: public");<br>        header("Expires: -1");<br>        header("Cache-Control: public, must-revalidate, post-check=0, pre-check=0");<br>        header("Content-Disposition: attachment; filename=\"$file_name\"");<br> <br>        // set appropriate headers for attachment or streamed file<br>        if ($is_attachment)<br>                header("Content-Disposition: attachment; filename=\"$file_name\"");<br>        else<br>                header('Content-Disposition: inline;');<br> <br>        // set the mime type based on extension, add yours if needed.<br>        $ctype_default = "application/octet-stream";<br>        $content_types = array(<br>                "exe" => "application/octet-stream",<br>                "zip" => "application/zip",<br>                "mp3" => "audio/mpeg",<br>                "mpg" => "video/mpeg",<br>                "avi" => "video/x-msvideo",<br>        );<br>        $ctype = isset($content_types[$file_ext]) ? $content_types[$file_ext] : $ctype_default;<br>        header("Content-Type: " . $ctype);<br> <br>        //check if http_range is sent by browser (or download manager)<br>        if(isset($_SERVER['HTTP_RANGE']))<br>        {<br>            list($size_unit, $range_orig) = explode('=', $_SERVER['HTTP_RANGE'], 2);<br>            if ($size_unit == 'bytes')<br>            {<br>                //multiple ranges could be specified at the same time, but for simplicity only serve the first range<br>                //<a href="http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt">http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt</a><br>                list($range, $extra_ranges) = explode(',', $range_orig, 2);<br>            }<br>            else<br>            {<br>                $range = '';<br>                header('HTTP/1.1 416 Requested Range Not Satisfiable');<br>                exit;<br>            }<br>        }<br>        else<br>        {<br>            $range = '';<br>        }<br> <br>        //figure out download piece from range (if set)<br>        list($seek_start, $seek_end) = explode('-', $range, 2);<br> <br>        //set start and end based on range (if set), else set defaults<br>        //also check for invalid ranges.<br>        $seek_end   = (empty($seek_end)) ? ($file_size - 1) : min(abs(intval($seek_end)),($file_size - 1));<br>        $seek_start = (empty($seek_start) || $seek_end < abs(intval($seek_start))) ? 0 : max(abs(intval($seek_start)),0);<br> <br>        //Only send partial content header if downloading a piece of the file (IE workaround)<br>        if ($seek_start > 0 || $seek_end < ($file_size - 1))<br>        {<br>            header('HTTP/1.1 206 Partial Content');<br>            header('Content-Range: bytes '.$seek_start.'-'.$seek_end.'/'.$file_size);<br>            header('Content-Length: '.($seek_end - $seek_start + 1));<br>        }<br>        else<br>          header("Content-Length: $file_size");<br> <br>        header('Accept-Ranges: bytes');<br> <br>        set_time_limit(0);<br>        fseek($file, $seek_start);<br> <br>        while(!feof($file)) <br>        {<br>            print(@fread($file, 1024*8));<br>            ob_flush();<br>            flush();<br>            if (connection_status()!=0) <br>            {<br>                @fclose($file);<br>                exit;<br>            }            <br>        }<br> <br>        // file save was a success<br>        @fclose($file);<br>        exit;<br>    }<br>    else <br>    {<br>        // file couldn't be opened<br>        header("HTTP/1.0 500 Internal Server Error");<br>        exit;<br>    }<br>}<br>else<br>{<br>    // file does not exist<br>    header("HTTP/1.0 404 Not Found");<br>    exit;<br>}<br>?><br></div></div>