Welcome, Guest
Username: Password: Remember me

TOPIC: [SOLVED] Upload not working - Mime detection

[SOLVED] Upload not working - Mime detection 25 Apr 2012 00:23 #2120

  • edwardcox
  • edwardcox's Avatar
  • Offline
  • Premium Member
  • Here to help.
  • Posts: 131
  • Thank you received: 26
  • Karma: 12
Hi All,

Apologies for the double posting, but I believe there is still an issue with File Upload:

Sorry, but after fresh regenerate and download this morning I am still unable to use Upload File.
Mime type not valid (application/force-download), allowed Mimes are text/plain - image/bmp - image/vnd.wap.wbmp - application/msword - image/gif - text/html - image/vnd.microsoft.icon - image/iff - image/jp2 - image/jpeg - application/pdf - image/png - image/psd - text/rtf - application/x-shockwave-flash - application/x-gzip - image/tiff - image/xbm - application/x-zip :
There were some upload errors

In the File Upload field on Front End I have tried All of the above FileTypes to no avail.

I should note that this does work OK in the sandbox.

My Component (Quote Please) worked fine last week, no changes made my end, screen cap of settings in Table below.



Help please?

Thank you,

Edward.
Passionate Joomla! Developer and J-Cook pro evangelist.
www.jcombuilder.com - we build great Joomla!® Components so you don't have to.
Last Edit: 27 Apr 2012 11:24 by admin.
The administrator has disabled public write access.

Upload not working - Mime detection 25 Apr 2012 10:54 #2123

  • molenwal1
  • molenwal1's Avatar
  • Offline
  • Senior Member
  • Posts: 63
  • Thank you received: 17
  • Karma: 3
Hi Edward,

What type of file do you want to upload? In the message i see application/force-download as mime type that you want to upload. This mime type is set in the function getMime of the file class (classes\file.php) when there is no mime method set or mime type found.

Maybe it is a problem on your webserver that it cannot find a method to call the mime decodage.

Otherwise you can test when you add the mime type application/force-download in the Joomla Media Manager -> Options to the Legal Mime Types. Look if the file is accepted or maybe you will have another error message.

Adriaan
Molenwal1 Webdesign
www.molenwal1.nl
The administrator has disabled public write access.

Upload not working - Mime detection 25 Apr 2012 11:10 #2124

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
What about the sandbox ?
Can you upload ?

I think also a problem of mime detection.

Try ti disable the mime detection, it is not a security check. Only for ergonomy.

@molenwal1 :
Joomla Media Manager doesn't always check mime type. It depends...
So it can pass with com_media and not with your component.
Coding is now a piece of cake
The administrator has disabled public write access.

Upload not working - Mime detection 25 Apr 2012 11:51 #2125

  • edwardcox
  • edwardcox's Avatar
  • Offline
  • Premium Member
  • Here to help.
  • Posts: 131
  • Thank you received: 26
  • Karma: 12
Hello Adriaan & Jocelyn,

I am wanting users to be allowed to File Upload: .doc .txt .pdf .zip and .rtf file types.

Sandbox works fine.

Disabled Mime Type checking from Options in Media Manager / Components, still no joy.

Please throw some more suggestions my way? (I'm also checking everything three times, just in case)

Edward.

P.S. I have now enabled all Mime Types in the Properties for the File Upload Data Type. Still no success, same error.

BUT, I can upload a PNG. Just not the mime filetypes I really want. :-)
Passionate Joomla! Developer and J-Cook pro evangelist.
www.jcombuilder.com - we build great Joomla!® Components so you don't have to.
Last Edit: 25 Apr 2012 12:04 by edwardcox. Reason: Additional Info
The administrator has disabled public write access.

Upload not working - Mime detection 25 Apr 2012 12:02 #2126

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
I will check this as soon as possible.
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: edwardcox

Upload not working - Mime detection 26 Apr 2012 08:07 #2144

  • edwardcox
  • edwardcox's Avatar
  • Offline
  • Premium Member
  • Here to help.
  • Posts: 131
  • Thank you received: 26
  • Karma: 12
Further investigation from my end: created new "up" Project, 1 table, 2 fields (string and File), both fields in back and front end.

Mime-types that should be 'allowed': pdf, png, doc, jpg, txt, zip

Sandbox accepted: png / jpeg / pdf / doc / txt
Sandbox rejected: zip

Localhost accepted: png / jpeg /
Localhost rejected: pdf / doc (wont accept .docx - Mac Word) / zip (says it's a gz file) / txt

Online hosting same as Localhost results.

Still lost for ideas - but quite desperate to allow new users to upload files as part of their Online Quotation Request.

Thank you,

Edward.
Passionate Joomla! Developer and J-Cook pro evangelist.
www.jcombuilder.com - we build great Joomla!® Components so you don't have to.
The administrator has disabled public write access.

Upload not working - Mime detection 27 Apr 2012 08:03 #2154

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
If you can upload some and not others, that means the detected mime is incorrect.

Can you dump the detected mimes ?

In the classes/file.php :
function getMime($file)
{
	if (!self::exists($file))
		return null;

	$mime = null;

	//prefered order methods to call the mime decodage
	$mimeMethods = array(
		'mime_content_type',
		'finfo_file',
		'image_check',
		'system',
		'shell_exec',
	);

	foreach($mimeMethods as $method)
	{
		...
	}
	exit($mime);		//HERE
		
	...
}

It is possible Cook mime list is wrong.
The list of accepted mimes are written in your controller. You can change mimes declarations if wrong.
Coding is now a piece of cake
Last Edit: 27 Apr 2012 08:05 by admin.
The administrator has disabled public write access.

Upload not working - Mime detection 27 Apr 2012 09:50 #2156

  • edwardcox
  • edwardcox's Avatar
  • Offline
  • Premium Member
  • Here to help.
  • Posts: 131
  • Thank you received: 26
  • Karma: 12
Sorry, dumb question. So I insert the exit($mime); statement at the end of the foreach loop? (to exit and display the value of $mime) ?

That did nothing (even after I ensured that error_reporting was on). Just blank screen on execution. And nothing in my system error log either. Odd.

At this stage in the Project I have enabled ALL mime-types as allowed in the File data type and in the Content / Media Manager / Options, Restrict mime types = no, check = no.

Thank you,

Edward. (now pulling hair out).
Passionate Joomla! Developer and J-Cook pro evangelist.
www.jcombuilder.com - we build great Joomla!® Components so you don't have to.
The administrator has disabled public write access.

Upload not working - Mime detection 27 Apr 2012 09:57 #2157

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
If some files are working, it should output some mime.

By the way, try to avoid mime detection in the classes/upload.php file :
function checkMime($fileMime)
{
	return true;		//HERE

	$valid = false;
	if (isset($this->allowedTypes) && count($this->allowedTypes))
	foreach($this->allowedTypes as $mime => $ext)
	{
		$mime = preg_replace("#\/#", "\\\/", $mime);
		if (preg_match("/" . $mime . "/", $fileMime))
			$valid = true;
	}
	return $valid;
}
Coding is now a piece of cake
The administrator has disabled public write access.

Upload not working - Mime detection 27 Apr 2012 10:07 #2158

  • edwardcox
  • edwardcox's Avatar
  • Offline
  • Premium Member
  • Here to help.
  • Posts: 131
  • Thank you received: 26
  • Karma: 12
Avoided checkMime at least now seeing:
Mime type not valid (application/force-download), allowed Mimes are image/bmp - image/vnd.wap.wbmp - application/msword - image/gif - text/html - image/vnd.microsoft.icon - image/iff - image/jp2 - image/jpeg - application/pdf - image/png - image/psd - text/rtf - application/x-shockwave-flash - application/x-gzip - image/tiff - text/plain - image/xbm - application/x-zip :
        There were some upload errors

Is it significant that the application/force-download is first on the list?
Passionate Joomla! Developer and J-Cook pro evangelist.
www.jcombuilder.com - we build great Joomla!® Components so you don't have to.
The administrator has disabled public write access.

Upload not working - Mime detection 27 Apr 2012 10:46 #2159

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
The raised error come from:
classes/upload.php
function uploadFile($uploadFile, $options = array())
{
	...

//CHECK MIME HEADER
	/*	//TRY TO COMMENT THIS
	$this->file->mime = $this->getMime($this->file->tmp);
	if (!$this->checkMime($this->file->mime))
	{
		$app->enqueueMessage(JText::sprintf( "DEMO120_UPLOAD_MIME_TYPE_NOT_VALID_ALLOWED_MIMES_ARE",
											$this->file->mime,
											$this->getAllowedMimes()), 'error');
		return false;
	}
	*/
	
	...

}

If checkMime() returns true, it should not happens !

Try debug the steps in this function. (uploadFile() )

Maybe, you are not writing in the good files ;-)
It often happens to me to confuse the roots of differents projects of copy of them.
Coding is now a piece of cake
Last Edit: 27 Apr 2012 10:48 by admin.
The administrator has disabled public write access.

Upload not working - Mime detection 27 Apr 2012 11:13 #2160

  • edwardcox
  • edwardcox's Avatar
  • Offline
  • Premium Member
  • Here to help.
  • Posts: 131
  • Thank you received: 26
  • Karma: 12
Just an 'out of the blue' question.. would the fact that I'm using Mac OS X possibly have any bearing on the situation (regarding file integrity??).

In addition to my Component 'Quote Please' which will upload nothing (in fact I went back to the Cook project, removed the File data type from the Table, re added it just in case, re downloaded my project, reinstalled it) I also have added the dummy 'up' project to the site (just the 2 fields; string and File) to see if there was any difference.. no, same.



The above was an attempt to upload a Word document (on Mac OS X extension [hidden] is .docx)

And this was a .zip file:


Now, the good news. As expected, commenting out the Check Mime Type in upload.php Worked! Yeah Team!
So, I guess that's a work around - but not a fix ;-)

Edward.

P.S. just stumbled upon this earlier post :

http://www.j-cook.pro/forum/32-trouble-shooting/1540-upload-not-working#2161
Passionate Joomla! Developer and J-Cook pro evangelist.
www.jcombuilder.com - we build great Joomla!® Components so you don't have to.
Last Edit: 27 Apr 2012 11:23 by edwardcox. Reason: additional info
The administrator has disabled public write access.

Upload not working - Mime detection 27 Apr 2012 11:22 #2162

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Yes, mime detection is little but struggling in php, depending plateforms.

docx extension is not listed in Cook Self Service.
There are thousands of different mime and extensions, so the builder only furnish you some of them.

About your project :
All I want to know is what are the detected mimes for files that are working.


I move the topic in Troubeshooting now because it is not a Cook issue.
If you try to instance mime detection out of Cook, it will not work better.

If somebody find a real issue in this part of the code, I will have a closer look on.

Whatever... Mime detection is not a must, it is not a security check.
If it is not working, avoid it.
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: edwardcox

Re: Upload not working - Mime detection 27 Apr 2012 11:26 #2164

  • edwardcox
  • edwardcox's Avatar
  • Offline
  • Premium Member
  • Here to help.
  • Posts: 131
  • Thank you received: 26
  • Karma: 12
For now, I will move on and work with what is working. I will attempt to get the detected mimes a little later (only file I had success with was .png). All good, I will keep digging. :) Thanks for you help Jocelyn.

Edward.
Passionate Joomla! Developer and J-Cook pro evangelist.
www.jcombuilder.com - we build great Joomla!® Components so you don't have to.
The administrator has disabled public write access.
Time to create page: 0.087 seconds

Get Started