Serving Downloadable Assets For The PlayStation 3 With PHP

Version 2008-06-03.15

This article is a quick how-to put together from a series of experiments I conducted with a custom PHP page written to push a binary file down to an end-user and my PS3. I used a separate domain on this web server to mess with it, but didn't seem to disrupt anything.

My starting point was the PHP manual's readfile page. The excellent set of comments eventually showed the evolution of a couple of good chunks of code to read files safely from the web server.

Note: These experiments cover a PS3 running the 1.70 firmware. Future firmware versions may change this behavior.

PHP Tips
You must use a custom page to push the file down to the PS3 web browser. A typical link to a file may work, but may not send the file size, and may not send the content type properly if your host has not properly configured the web server.

Here is a sample chunk of code:

header("Content-type: $s_content_type");
header("Content-Disposition: attachment; filename=".basename($s_file));
header("Content-Length: ".@filesize($s_file));

Here's the breakdown:

Content-type
Videos: The content type can be set to "application/x-download" if you wish. This appeared to work in my tests, leading me to guess that the PS3 probably uses the filename in the content-disposition statement to judge what it is. Or you can use the real type, such as "video/mpeg" or "video/mpeg-2".
Themes: The content type of "application/x-ps3-theme" is necessary.

Content-Disposition:
You must NOT put quotes around the filename, or a semicolon after it.
Several examples do just that on various PHP pages, and that won't work. The PS3 will ask you for media to download a file to, which seems to be its way of protecting itself from unknown file types.
You must NOT put spaces in the filename.
You can't write a filename with spaces into it. While using the urlencode function on the file variable before it gets written here will let the PS3 download the file, it will appear as Unsupported Data in the XMB.

Content-Length
Without the length, users will not be permitted to put the download onto the background downloading queue on their PS3, and their PS3 will not display a proper percentage-complete bar. Note that themes cannot be downloaded in the background in any case.

More headers
There are more headers mentioned on the readfile page linked to earlier. They deal with cache controls, but don't seem to be necessary for downloads to succeed.

More PHP tips
Use the readfile_chunked function on the aforementioned page. It will apparently save you some pain and suffering, and don't forget to set the timeout to zero when pushing a file down in case it's a big one. Finally, note that if you're using mod_bw or a similar bandwidth throttling module with apache to limit download speeds, the name of the script file itself will be what determines what filter is tripped, not the much larger video file itself. That means the video file will download as fast as you let php files be downloaded -- something which is typically not throttled.

A Word About Video formats
The following video formats worked on my PS3 when encoded by Ulead's VideoStudio 10 Plus.
mpeg-1 (352x240)
mpeg-2
mpeg-2 HD (1440x1080 at 29 fps)

These formats did NOT work, resulting in Unsupported Data objects on the XMB:
mpeg-4 720x480

More To Come?
Look for more information to join this page if and when I get the chance to tinker further.

Enjoy!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <embed> <object> <param>
  • Lines and paragraphs break automatically.
  • You can use BBCode tags in the text. URLs will automatically be converted to links.

More information about formatting options

CAPTCHA
Be ye bot or be ye not?