header("Content-type: image/png"); makes script run twice?
Pirata Nervo Offline
Member
***
Posts: 235
Joined: Jan 2008
Post: #1
header("Content-type: image/png"); makes script run twice?
Hey,

I've been searching for an hour and doing tests myself and found out the issue for my script being executed twice - queries are getting executed twice so I believe the script is also run twice.

Here's the problem:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
switch($dl['filetype'])
	{
		case "application/pdf":
		case "image/bmp":
		case "image/gif":
		case "image/jpeg":
		case "image/pjpeg":
		case "image/png":
		case "text/plain":
			header("Content-type: {$dl['filetype']}");
			//header("Content-type: application/force-download");
			$disposition = "inline";
			break;

		default:
			header("Content-type: application/force-download");
			$disposition = "attachment";
	}


If I comment:

PHP Code:
header("Content-type: {$dl['filetype']}");


And uncomment the first:

PHP Code:
header("Content-type: application/force-download");


The script is executed twice. I have no idea why and can't seem to find anything related to this on the internet. If the script forces download, this no longer happens.

Note that if I comment:

PHP Code:
echo file_get_contents(MYBB_ROOT.$mybb->settings['mydownloads_downloads_dir']."/".$dl['download']);


Which is a bit below that, then the problem no longer happens either (but with it uncommented and with force-download, it doesn't happen either).

This is the only thing I could find related to this problem but doesn't help at all:

Quote:When using readfile()  -or fopen() and fpassthru() - make sure that if you are dealing with large files that are located on your server, use absolute paths and not URL's! Otherwise, the file will essentially be downloaded twice - the script will access the file from your web server itself, and then output it to the client, doubling the bandwidth. I made this mistake in a download script I made that included files on other servers, when the file was on mine, I forgot to use absolute paths. So, even for good practice if your files you're accessing are small, use absolute paths whenever possible. Seems obvious, but don't forget about it.
http://www.theserverpages.com/php/manual...http://www.theserverpages.com/php/manual/en/function.fpa

(I've tried full path and URL, both give me the same weird results: queries are getting executed twice)
Okay, it seems the problem is this:

PHP Code:
$disposition = "inline";


Gotta check what's wrong with inline disposition.



Alright some more information, it seems that only images are affected. I've found this related article: http://forums.mysql.com/read.php?52,1143...http://forums.mysql.com/read.php?52,114324,114324#

It's the same problem as I described but the solution is not good enough..


Okay after some deep testing the problems seems to affect images only and ONLY when the request is not sent via POST because if we send via POST it works fine (switching to POST only would fix this issue but fixing the actual problem would be better I guess...)
(This post was last modified: 06-22-2011 03:13 AM by Pirata Nervo.)
06-22-2011 02:54 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
header("Content-type: image/png"); makes script run twice? - Pirata Nervo - 06-22-2011 02:54 AM

 Standard Tools
Forum Jump: