Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks for everyone's answers. </p> <p>I actually ended up solving the problem without revealing the path to the audio file to the user. </p> <p>Because this is for an online voice messaging application, it was important to protect the path to the messages in order to protect the user's privacy. </p> <p>The situation ended up being further complicated by the fact that the messages are stored on a remote server... found this out right after I posted this question. </p> <p>So all in all the process was: </p> <p>1) Curl the MP3 file from the remote server</p> <p>2) Set some headers to force the download of the data, which you then echo to stdout</p> <p>Because the data is being put on standard out and the headers are set to force a download, the effect for jPlayer is the same as if it had requested a file at /some/dir/message.mp3, except that the request goes to /some/dir/playmessage.php - thus the path is never revealed to the user. </p> <p>EDIT** - <strong>Assume that I have access control, validation running before the snippit below, otherwise exposing the path to the script below is no different than just exposing the path to the mp3. (see comments between me and Lloyd)</strong></p> <p>Here's the code that ended up getting the job done: </p> <pre><code>$ch = curl_init($remoteFile); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); $data = curl_exec($ch); curl_close($ch); if ($data === false) { echo 'CURL Failed'; exit; } //Get file size if (preg_match('/Content-Length: (\d+)/', $data, $matches)) { $contentLength = (int)$matches[1]; } //force user to download file contents header('Content-Transfer-Encoding: binary'); header('Content-Type: audio/mpeg'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Content-Length: ' . $contentLength); ob_clean(); flush(); echo $data; exit; ?&gt; </code></pre> <p>Assume that <code>$remoteFile</code> is a path to the mp3 file that I want to play on the server where we are storing messages.</p> <p>I found this resource on <a href="http://www.php-mysql-tutorial.com/wikis/php-tutorial/reading-a-remote-file-using-php.aspx" rel="nofollow">reading a remote file using PHP</a> especially helpful. Here's some more information on <a href="http://www.jonasjohn.de/snippets/php/headers.htm" rel="nofollow">modifying http headers</a>.</p> <p><strong>NOTE</strong> I am essentially downloading the file twice, which slows the process down for the user. There is probably a better way to do this. :) If you kept the file locally, what I had initially in my question actually works (using readfile() to output the raw mp3 data). </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload