0

Hai frnds i am new to php actually i am facing following problems in coding please can anyone give the solution?

  1. Actually i am having one audio player and i am displaying some word dcoument
  2. if i click word document corresponding audio file should play
  3. actually when i click doc file it should pop ip with save as and open with for that i am using some header code
  4. also i am passing query string in the browser
  5. query string is not working if i use header

can anyone give me a solution for it below is my code i am attaching

<?php

$f_name = $_POST["fn"];
$id = $_POST["id1"];
echo $id;
//echo "../public_html/sites/default/files/ourfiles/$f_name";
$res2=db_query("select * from mt_files where id='".$id."' ");
$row2=db_fetch_array($res2);

$job_audio=$row2["audio_name"];
//echo $job_audio;
//$job_audi=explode("/",$job_audio);
//$job_audio=$job_audi[8];
$job_audio= "C:/xampp/htdocs/med/sites/default/files/audio/$job_audio";
//$job_audio= "C:/Documents and Settings/swuser/My Documents/$job_audio";
//echo $job_audio;


echo "<object data='$job_audio' type='application/x-mplayer2' width='150' height='45'>
<param name='src' value='$job_audio'>
<param name='autoplay' value='true'>
<param name='autoStart' value='1'>

</object> ";


$file = "../mts/sites/default/files/docs/$f_name";

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}

//The download table query goes here put the $f_name in insert into with the //time varible


?>
1
  • I don't understand your problem. The example does not show any use of a HTTP query string. Should you use $_REQUEST instead of $_POST? Commented May 27, 2010 at 7:18

1 Answer 1

3

I don't understand either, but you can't do

echo ...

Before calling the header() function.

Isn't that your problem ?

Remove any output before any header() calls and it will work... better

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.