tim9000 Posted September 4, 2009 Share Posted September 4, 2009 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*); flush(); } fclose($stream); } Link to comment https://forums.phpfreaks.com/topic/173091-opening-flash-file-using-php-header/ Share on other sites More sharing options...
BinaryG Posted September 4, 2009 Share Posted September 4, 2009 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 https://forums.phpfreaks.com/topic/173091-opening-flash-file-using-php-header/#findComment-912351 Share on other sites More sharing options...
tim9000 Posted September 4, 2009 Author Share Posted September 4, 2009 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 https://forums.phpfreaks.com/topic/173091-opening-flash-file-using-php-header/#findComment-912363 Share on other sites More sharing options...
BinaryG Posted September 4, 2009 Share Posted September 4, 2009 thats better it works perfectly fine in both firefox and ie8 for me are you sure you have flash installed on ie Link to comment https://forums.phpfreaks.com/topic/173091-opening-flash-file-using-php-header/#findComment-912364 Share on other sites More sharing options...
tim9000 Posted September 4, 2009 Author Share Posted September 4, 2009 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 https://forums.phpfreaks.com/topic/173091-opening-flash-file-using-php-header/#findComment-912384 Share on other sites More sharing options...
tim9000 Posted September 4, 2009 Author Share Posted September 4, 2009 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 https://forums.phpfreaks.com/topic/173091-opening-flash-file-using-php-header/#findComment-912644 Share on other sites More sharing options...
mattal999 Posted September 4, 2009 Share Posted September 4, 2009 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 https://forums.phpfreaks.com/topic/173091-opening-flash-file-using-php-header/#findComment-912655 Share on other sites More sharing options...
tim9000 Posted September 4, 2009 Author Share Posted September 4, 2009 Thanks mattal999, I assume that it's generally better to do it in your way, but unfortunately it did help on this matter. Link to comment https://forums.phpfreaks.com/topic/173091-opening-flash-file-using-php-header/#findComment-912677 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.