Jump to content

Wrong Mimetype Output (HTML Doc instead of rar or zip)


Irap

Recommended Posts

The file being outputted is a .rar

 

	# $file['filename'] = "myfile.rar"; // given by database

	$file['extension'] = substr( $file['filename'], -3 );

	// Set the mime according to the extension.
	// I believe these are appropriate mime types to use.
	if ( $file['extension'] == "rar" )
	{
		$file['mime'] = "application/x-rar-compressed";
	}
	elseif ( $file['extension'] == "zip" )
	{
		$file['mime'] = "application/zip";
	}

	// Added the if statement just in case the above wasn't working.
	if ( $file['mime'] == "application/zip" || $file['mime'] == "application/x-rar-compressed" )
	{
		mysql_query("
			UPDATE `web_downloads_mods`
			SET `downloads` ='{$file_mod['file_downloads']}'
			WHERE `id` ='{$file['id']}'
			LIMIT 1
		");

		@header( "Expires: ".gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y")))." GMT" ); # expire the file in 2 hours.
		@header( "Last-Modified: " . gmdate("D, d M Y H:i:s", $file['uploaded']) . " GMT" );
		@header( "Content-Length: {$file['filesize']}" ); # given by the database in bytes.
		@header( "Content-Disposition: attachment; filename='". $file['filename'] ."'" );
		// Internet Explorer compatibility:
		@header( "Pragma: " );
 		@header( "Cache-Control: " );

		readfile( "http://". $_SERVER['HTTP_HOST'] ."/uploads/". $file['filename'] );
	}

 

Firefox will open the file in a new tab and display gibberish...

 

Except, of course... At the beginning of the file there is a fun "Rar!". Is this something that occurs in many files and can be used to test if files are the right extension?

Link to comment
Share on other sites

Heh, I thought I had used content type.

 

 

The problem with PHP outputting errors is that it messes up the file that is being printed. As they say, don't output anything else besides from the file data when using header() to output files... Otherwise you get an error at the start of the file.

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.