-2

i want to solution download file into php I am using this way to download file but getting issue download file code

$filename = '[file name].[extension]';

$file="application/[extension]";


if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');

problem:

2 Answers2

0

Here is basic example to download file -

$file="http://example.com/filename.mp3"; // your filename with path
header("Content-type: application/x-file-to-save"); 
header("Content-Disposition: attachment; filename=".basename($file)); 
readfile($file);
exit;
TBI
  • 2,789
  • 1
  • 17
  • 21
  • you have to give file name with path in $file not directory...remove songs from $file and assign filename under songs directory – TBI Aug 21 '14 at 06:54
  • i am not getting your problem with database...is your file stored in database ? – TBI Aug 21 '14 at 07:15
  • ok...get that file from database and assign it to $file variable – TBI Aug 21 '14 at 07:26
  • why after download ?? you have to fetch it before your download script. You need to post another question if you want to know about fetch data from database – TBI Aug 21 '14 at 07:36
  • still your question is unclear...you want to download all the files from songs folder ?? – TBI Aug 21 '14 at 09:12
0

Try this Follow the instruction by variable.... Use file path not filename

 header("Content-Transfer-Encoding: Binary");
        header("Content-length: ".filesize($dest_file_path));
        header('Content-Type: text/xml');
        header('Content-Disposition: attachment; filename="'.$dest_file_name.'"');
        readfile($dest_file_path);
Torrezzzz
  • 307
  • 2
  • 13