Jump to content

Opening flash file using php header()


tim9000

Recommended Posts

I'm trying to open swf file using php headers but I'm having major problem with IE browsers although it works perfectly ok in Firefox. IE seems to load something but the output is just blank page.

 

The script that I'm using is:

 

$file = "FILENAME_HERE";

$file_real = $file;

 

//if (file_exists($file)){

// Get extension of requested file

 

$extension = strtolower(substr(strrchr($file, "."), 1));

 

// Determine correct MIME type

 

switch($extension){

case "flv": $type = "flv-application/octet-stream"; break;

case "mp4": $type = "video/mp4"; break;

case "swf": $type = "application/x-shockwave-flash"; break;

default: $type = "application/force-download"; break;

}

 

// Fix IE bug [0]

 

$header_file = (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) ? preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1) : $file;

 

// Prepare headers

 

header("Pragma: public");

header("Expires: 0");

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

header("Cache-Control: public", false);

header("Content-Description: File Transfer");

header("Content-Type: " . $type);

header("Accept-Ranges: bytes");

header("Content-Transfer-Encoding: binary");

 

// Send file for download

 

if ($stream = fopen($file_real, 'rb')){

while(!feof($stream) && connection_status() == 0){

 

//reset time limit for big files

 

set_time_limit(0);

print(fread($stream,1024*8));

flush();

}

fclose($stream);

}

Link to comment
Share on other sites

well i cant get that script to work in any borwser with ether remote or local swf files i just get a full page with movie not loaded but a quick tip put your code in code tags it the # button on the create post screen. i must admint i have not done much work with php headers but could you post a bit more info on the script maybe one with a link to a swf file that works for you.

Link to comment
Share on other sites

Oops - code was messed up - sorry...

New try...

 

<?php
$file = 'FILE_NAME_HERE';
$file_real = $file;

//if (file_exists($file)){
// Get extension of requested file

$extension = strtolower(substr(strrchr($file, "."), 1));

// Determine correct MIME type

switch($extension){
case "flv": $type = "flv-application/octet-stream"; break;
case "mp4": $type = "video/mp4"; break;
case "swf": $type = "application/x-shockwave-flash"; break;
default: $type = "application/force-download"; break;
}

// Fix IE bug

$header_file = (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) ? preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1) : $file;

// Prepare headers

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public", false);
header("Content-Description: File Transfer");
header("Content-Type: " . $type);
header("Accept-Ranges: bytes");
header("Content-Transfer-Encoding: binary");

// Send file for download

if ($stream = fopen($file_real, 'rb')){
while(!feof($stream) && connection_status() == 0){

//reset time limit for big files

set_time_limit(0);
print(fread($stream,1024*);
flush();
}
fclose($stream);
}
?>

Link to comment
Share on other sites

Thanks BinaryG - I actually managed somehow to get that to work while copy-pasting it here - weird.

 

Although that is just part of the script that I'm using (so the main problem is somewhere else).

 

What I'm trying to achieve is to be able to check if given access code is valid to show the data provided.

I have working script for the downloading enabled files but if I use the same code for playing files (in the last post) I hit the error with the IE...

 

Sorry for trying to cut corners in the first post (I don't know how I didn't get even that code to work)

 

Need to analyse the whole code more...

Link to comment
Share on other sites

Ok - here is the simplified version of the code that I'm trying to use which causes the problem with the IE:

 

I'm trying to create script that shows the "hidden" swf file only after the correct input...

 

<?php
$id = $_POST["code"];

if ($id == ''){
$error ="";
}
elseif ($id < 1){
$error ="less than one";
}
else{
$file = 'FILENAME_HERE';
$file_real = $file;

//if (file_exists($file)){
// Get extension of requested file

$extension = strtolower(substr(strrchr($file, "."), 1));

// Determine correct MIME type

switch($extension){
case "flv": $type = "flv-application/octet-stream"; break;
case "mp4": $type = "video/mp4"; break;
case "swf": $type = "application/x-shockwave-flash"; break;
default: $type = "application/force-download"; break;
}

// Fix IE bug

$header_file = (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) ? preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1) : $file;

// Prepare headers

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public", false);
header("Content-Description: File Transfer");
header("Content-Type: " . $type);
header("Accept-Ranges: bytes");
header("Content-Transfer-Encoding: binary");

// Send file for download

if ($stream = fopen($file_real, 'rb')){
while(!feof($stream) && connection_status() == 0){

//reset time limit for big files

set_time_limit(0);
print(fread($stream,1024*);
flush();
}
fclose($stream);
}
}
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>code test</title>
</head>
<body>
<form action='' method='post'>code: <input type='text' name='code' /><input type='submit' value='submit' /></form>
<br /><?php echo $error ?>
</body>
</html>

Link to comment
Share on other sites

Not sure about this, but is it because you are sending HTML after sending the swf?

 

<?php
$id = $_POST["code"];
if(isset($id)) {
if ($id == ''){
$error ="";
}
elseif ($id < 1){
$error ="less than one";
}
else{
$file = 'FILENAME_HERE';
$file_real = $file;

//if (file_exists($file)){
// Get extension of requested file

$extension = strtolower(substr(strrchr($file, "."), 1));

// Determine correct MIME type

switch($extension){
case "flv": $type = "flv-application/octet-stream"; break;
case "mp4": $type = "video/mp4"; break;
case "swf": $type = "application/x-shockwave-flash"; break;
default: $type = "application/force-download"; break;
}

// Fix IE bug

$header_file = (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) ? preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1) : $file;

// Prepare headers

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public", false);
header("Content-Description: File Transfer");
header("Content-Type: " . $type);
header("Accept-Ranges: bytes");
header("Content-Transfer-Encoding: binary");

// Send file for download

if ($stream = fopen($file_real, 'rb')){
while(!feof($stream) && connection_status() == 0){

//reset time limit for big files

set_time_limit(0);
print(fread($stream,1024*);
flush();
}
fclose($stream);
}
}
} else {
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>code test</title>
</head>
<body>
<form action='' method='post'>code: <input type='text' name='code' /><input type='submit' value='submit' /></form>
<br /><?php echo $error ?>
</body>
</html>
<?php 
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.