I have a Text file created by php script using str_pad() with spaces, I want to download the same without losing those spaces. When I download using ftp, there is no issue, all the spaces in the text files are intact. But when I use this download script so that the user can download, it gives junk characters instead of spaces and data is scrambled. Pl help if there is any other way of downloading this file by the user.My php file to download - download.php:\[code\]<?phpfunction output_file($file, $name, $mime_type=''){if(!is_readable($file)) die('File not found or inaccessible!'); $size = filesize($file); $name = rawurldecode($name); $known_mime_types=array("txt" => "text/plain","html" => "text/html","php" => "text/plain" ); if($mime_type==''){ $file_extension = strtolower(substr(strrchr($file,"."),1)); if(array_key_exists($file_extension, $known_mime_types)){ $mime_type=$known_mime_types[$file_extension]; } else { $mime_type="application/force-download"; }; }; @ob_end_clean(); if(isset($_SERVER['HTTP_RANGE'])) {list($a, $range) = explode("=",$_SERVER['HTTP_RANGE'],2);list($range) = explode(",",$range,2);list($range, $range_end) = explode("-", $range);$range=intval($range);if(!$range_end) { $range_end=$size-1;} else { $range_end=intval($range_end);}$new_length = $range_end-$range+1;header("HTTP/1.1 206 Partial Content");header("Content-Length: $new_length");header("Content-Range: bytes $range-$range_end/$size"); } else {$new_length=$size;header("Content-Length: ".$size); } $chunksize = 1*(1024*1024); $bytes_send = 0; if ($file = fopen($file, 'r')) {if(isset($_SERVER['HTTP_RANGE']))fseek($file, $range);while(!feof($file) && (!connection_aborted()) && ($bytes_send<$new_length) ){ $buffer = fread($file, $chunksize); print($buffer); //echo($buffer); flush(); $bytes_send += strlen($buffer);} fclose($file); } else die('Error - can not open file.');die();}set_time_limit(0);$file_path=$_REQUEST['filename'];output_file($file_path, ''.$_REQUEST['filename'].'', 'text/plain');?>\[/code\]HTML file which calls the download.php\[code\]<html><head><title>Downloading Text file</title></head><body><br><br><a href='http://stackoverflow.com/questions/10545603/download.php?filename=Text1.txt'>Download print file </a><br><br><br></body></html>\[/code\]My original Text1.txt file output which is created by a php script using str_pad():\[code\] 3M India Ltd 78788 No.2, Abbayappa Layout, 4th Main, NS Palaya, Bannerghatta Road, Bangalore 560 076 11/05/2012 10:10:57 500 322 AAACB5984DXM001 29400127541 KA-01-N-2345 29400127541\[/code\]