Page 1 of 1

Downloadproblem with IE7

Posted: Thu 13. Dec 2007, 16:38
by metti
Hello!

For a customer i changed the download.php so that user is asked to download the file (even if it's mp3 or jpg).
Unfortunately this does not work for IE7 (i guess there are problems with the header-data): It displays the dialog "Save file...", downloads an says the download was successfull, but it is'nt because the file is empty.
For IE6 / FF etc. it works.

The code:
in download.php i change this

Code: Select all

headerRedirect(PHPWCMS_URL . PHPWCMS_FILES . $fileinfo['filename']);
to

Code: Select all

// Set content type        
            if (preg_match('#Opera(/| )([0-9].[0-9]{1,2})#', getenv('HTTP_USER_AGENT')) or 
                preg_match('#MSIE ([0-9].[0-9]{1,2})#', getenv('HTTP_USER_AGENT'))) {
                    
                $content_type = 'application/octetstream';
            } else {
                $content_type = 'application/octet-stream';
            }
    header("Content-Type: ".$content_type);
    header( 'Content-Length: ' . $fileinfo['filesize'] );
    header( 'Content-Disposition: attachment; filename="'.$download["f_name"].'"' ); 
    readfile(PHPWCMS_FILES . $fileinfo['filename']);
As a quick solution i made a switch:

Code: Select all

    if (preg_match('#MSIE (7.[0-9]{1,2})#', getenv('HTTP_USER_AGENT'))) {
    headerRedirect(PHPWCMS_URL . PHPWCMS_FILES . $fileinfo['filename']); }else{
    readfile(PHPWCMS_FILES . $fileinfo['filename']); }
Has anybody a idea of how to solve the IE7-problem?

Greetings an cheers,
Metti

Re: Downloadproblem with IE7

Posted: Mon 28. Jul 2008, 19:44
by metti
Hello. For some reasons i became have got a mail, that someone answered to this thread :? and so i remembered, that i had solved the problem some time ago but did not mention this here.

So there you are (This is the complete code of the download.php):

Code: Select all

<?php

/*************************************************************************************

   Copyright notice

   

   (c) 2002-2007 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.

 

   This script is part of PHPWCMS. The PHPWCMS web content management system is

   free software; you can redistribute it and/or modify it under the terms of

   the GNU General Public License as published by the Free Software Foundation;

   either version 2 of the License, or (at your option) any later version.

  

   The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html

   A copy is found in the textfile GPL.txt and important notices to the license 

   from the author is found in LICENSE.txt distributed with these scripts.

  

   This script is distributed in the hope that it will be useful, but WITHOUT ANY 

   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A

   PARTICULAR PURPOSE.  See the GNU General Public License for more details.

 

   This copyright notice MUST APPEAR in all copies of the script!

*************************************************************************************/



/*

if(ini_get('zlib.output_compression') && function_exists('ini_set')) {

	ini_set('zlib.output_compression', 'Off');

}

*/



$phpwcms = array();



require_once ('config/phpwcms/conf.inc.php');

require_once ('include/inc_lib/default.inc.php');

require_once (PHPWCMS_ROOT.'/include/inc_lib/dbcon.inc.php');



require_once (PHPWCMS_ROOT.'/include/inc_lib/general.inc.php');

require_once (PHPWCMS_ROOT.'/include/inc_lib/functions.file.inc.php');



// try to get hash for file download

$success	= false;

$hash		= false;

$countonly	= empty($_GET['countonly']) ? false : true;

$hash 		= empty($_GET['f']) ? '' : clean_slweg($_GET['f']);



if(empty($phpwcms["inline_download"])) {

	$phpwcms["inline_download"]		= empty($_GET['target']) ? 0 : 1;

}



if(!empty($hash) && strlen($hash) == 32) {



	// get file info - limit 1 entry

	$download = _getFileInfo($hash, 1);

	

	if(is_array($download) && count($download)) {

		// all we need is the first array value



		$download = current($download);



		// ok fine - we have download information

		// then count up download try for this file

		$sql  = "UPDATE ".DB_PREPEND."phpwcms_file ";

		$sql .= "SET f_dlstart=f_dlstart+1 WHERE ";

		$sql .= "f_hash='".aporeplace($download["f_hash"])."' LIMIT 1";

		@mysql_query($sql, $db);





		$fileinfo = array();

		

		$fileinfo['filename'] = $download["f_hash"];

		if($download["f_ext"]) {

			$fileinfo['filename'] .= '.'.$download["f_ext"];

		}



		// just count up a download

		if($countonly || 1) {



			$success = true;

			

		// just use built-in download

		} else {

		



			$fileinfo['path'] 		= PHPWCMS_ROOT.$phpwcms["file_path"];

			$fileinfo['filesize']	= $download['f_size'];

			$fileinfo['method']		= empty($phpwcms["inline_download"]) ? 'attachment' : 'inline';

			$fileinfo['mimetype']	= $download["f_type"];

			$fileinfo['file']		= $fileinfo['path'].$fileinfo['filename'];

			$fileinfo['extension']	= $download["f_ext"];

			$fileinfo['realfname']	= $download["f_name"];

					

			// start download

			$success = dl_file_resume($fileinfo['file'], $fileinfo, true);

		

		}

		



	}



}



if($success) {

  // Browsererkennung

  if (!empty($_SERVER['HTTP_USER_AGENT']))                $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];

  else if (!empty($HTTP_SERVER_VARS['HTTP_USER_AGENT']))  $HTTP_USER_AGENT = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];

  else if (!isset($HTTP_USER_AGENT))                      $HTTP_USER_AGENT = '';



  if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version))  $browser_agent = 'opera';

   else if (ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) $browser_agent = 'ie';

  

  $file = PHPWCMS_FILES . $fileinfo['filename'];

  $filename = $download["f_name"];

  if ( ($browser_agent == 'ie') || ($browser_agent == 'opera') ) $mimetype = 'application/octetstream';

  else  $mimetype = 'application/octet-stream'; 

  



	$sql  = "UPDATE ".DB_PREPEND."phpwcms_file ";

	$sql .= "SET f_dlfinal=f_dlfinal+1 WHERE f_hash='".aporeplace($download["f_hash"])."' LIMIT 1";

	@mysql_query($sql, $db);



	if(!$countonly) {

		header('Pragma: public');

    header('Content-Transfer-Encoding: none');

    header('Content-Type: ' . $mimetype . '; name="' . $filename . '"');

    if ($browser_agent == 'ie')      header('Content-Disposition: inline; filename="' . urlencode($filename) . '"');

    else                             header('Content-Disposition: attachment; filename=' . $filename);

    $size = $fileinfo['filesize'];

    if ($size > 0) header('Content-length: '.$size);else header('Content-length: '.@strlen(@file_get_contents($file)));

    readfile($file);

    exit;

	}else{

	  header('Location: '.$file);

  }

} else {



	header("HTTP/1.0 404 Not Found");

	echo '<strong>404 File Not Found</strong>';



}



exit();



?>


Re: Downloadproblem with IE7

Posted: Mon 28. Jul 2008, 20:01
by juergen
metti wrote:Hello. For some reasons i became a mail
:shock: I do honestly hope you GOT a mail :mrgreen:

Re: Downloadproblem with IE7

Posted: Mon 28. Jul 2008, 21:33
by metti
:D Oops. metti != mail :!: of course you're right. thx

Re: Downloadproblem with IE7

Posted: Mon 28. Jul 2008, 21:54
by Jensensen
many thanx for sharing your knowledge, guys.

Re: Downloadproblem with IE7

Posted: Mon 28. Jul 2008, 22:15
by metti
De rien :)

Now that i'm here after a long time: I need to get my page bilingual and know, that this is quiet difficult with phpwcms.

But: For wordpress there is a very nice plugin named xLanguage with that you can tag languages in your text within the TinyMCE-WYSIWYG-Editor.

You can find it here: http://hellosam.net/project/xlanguage
This plugin works by inserting W3C standardized <span lang=”..”> tag in the post content, and a XML parser will be involved to extract them when served, extracting all elements with the matching lang=”..” tag. The permalinks and RSS feeds are also presented correctly. For single line data such as post title, a special but simple syntax is introduced.
I'd like to get this plugin to work in phpwcms. What do you think: Would this be fine or is there a better way (with maybe less stress)?

Re: Downloadproblem with IE7

Posted: Mon 28. Jul 2008, 22:27
by update
just go ahead and contact OG whether there is something up like this (yes there is some: [DE]text[/DE] or simlarly working with the doc lang tag I suppose). But for translating very complex sites this would be a PITA probably...

Re: Downloadproblem with IE7

Posted: Mon 28. Jul 2008, 22:40
by metti
Okay. I will contact him. What do you mean would be a pita? The xlanguage or the [DE] solution?

Re: Downloadproblem with IE7

Posted: Mon 28. Jul 2008, 22:44
by update
both - if you have a lot of text and a lot of ContentParts it will become overwhelmingly confusing tagging the text (and some pages will contain different text or will not be needed in another language at all, so there should be a better solution (or I didn't get it right yet?)

Re: Downloadproblem with IE7

Posted: Mon 28. Jul 2008, 22:56
by metti
You're right. But the problem is, that multilingual sites always cost a lot of work.

Now that i saw the solutions with replacement tags i will do it this way - but not because i think it would be better but easyer to realize. The xLanguage-method is eventhough more comfortable (and is even the most comfortable way i ever saw to handle at least 2 languages - more could be a bit confusing in longer texts).

Another sugestion for a phpwcms language module would be an adaption of JoomFish.